예제 #1
0
파일: dir_rb.c 프로젝트: Cancerous/libxenon
int rb_rmdir(int volume, const char* name)
{
    int rc;
    RB_DIR* dir;
    struct rb_dirent* entry;
    
    dir = rb_opendir(volume, name);
    if (!dir)
    {
        errno = ENOENT; /* open error */
        return -1;
    }

    /* check if the directory is empty */
    while ((entry = rb_readdir(dir)))
    {
        if (rb_strcmp(entry->d_name, ".") &&
            rb_strcmp(entry->d_name, ".."))
        {
            DEBUGF("rmdir error: not empty\n");
            errno = ENOTEMPTY;
            rb_closedir(dir);
            return -2;
        }
    }

    rc = fat_remove(&(dir->fatdir.file));
    if ( rc < 0 ) {
        DEBUGF("Failed removing dir: %d\n", rc);
        errno = EIO;
        rc = rc * 10 - 3;
    }

    rb_closedir(dir);
    return rc;
}
예제 #2
0
char* item_item_key(char *item1, char *item2){
  int keylen = strlen(item1) + strlen(item2) + 2;
  char *key = (char *)malloc(keylen * sizeof(char));

  if(!key){
    printf("cannot allocate\n");
    return 0;
  }  

  // FIXPAUL: make shure this does exactly the same as ruby sort  
  if(rb_strcmp(item1, item2) <= 0){
    snprintf(key, keylen, "%s:%s", item1, item2);
  } else {
    snprintf(key, keylen, "%s:%s", item2, item1);
  }

  return key;
}