void levelorder(t_btree *root, void (*applyf)(void *item, int current_level, int is_first_elem), int *i, int *u) { t_iterativ **nxt; int *tab; t_iterativ *q; q = create_new(0, root, 0); tab = malloc(sizeof(int) * btree_level_count_if(root) * 10); nxt = malloc(sizeof(t_iterativ *) * btree_level_count_if(root) * 10); while (q) { applyf(q->node->item, q->level, q->is_first); if (q->node->left) { nxt[*i] = create_new(q, q->node->left, tab[q->level + 1]); *i += 1; tab[q->level + 1] = 1; } if (q->node->right) { nxt[*i] = create_new(q, q->node->right, tab[q->level + 1]); *i += 1; tab[q->level + 1] = 1; } q = nxt[*u]; *u += 1; } }
int dfs_open(struct file *filp, char *name) { struct filsys *fs; struct inode *inode; int rc; fs = (struct filsys *) filp->fs->data; switch (filp->flags & (O_CREAT | O_EXCL | O_TRUNC | O_SPECIAL)) { case 0: case O_EXCL: // Open existing file rc = open_existing(fs, name, &inode); break; case O_CREAT: // Open file, create new file if it does not exists rc = open_always(fs, name, filp->mode, &inode); break; case O_CREAT | O_EXCL: case O_CREAT | O_TRUNC | O_EXCL: // Create new file, fail if it exists rc = create_new(fs, name, NOINODE, filp->mode, &inode); filp->flags |= F_MODIFIED; break; case O_TRUNC: case O_TRUNC | O_EXCL: // Open and truncate existing file rc = truncate_existing(fs, name, &inode); filp->flags |= F_MODIFIED; break; case O_CREAT | O_TRUNC: // Create new file, unlink existing file if it exists rc = create_always(fs, name, filp->mode, &inode); filp->flags |= F_MODIFIED; break; case O_SPECIAL: // Create new file with special inode number rc = create_new(fs, name, filp->flags >> 24, filp->mode, &inode); filp->flags |= F_MODIFIED; break; default: return -EINVAL; } if (rc < 0) return rc; if (filp->flags & O_APPEND) filp->pos = inode->desc->size; filp->data = inode; filp->mode = inode->desc->mode; filp->owner = inode->desc->uid; filp->group = inode->desc->gid; return 0; }
static void init_ccnet () { char *config_dir = applet->config_dir; char *config_file; config_file = g_build_filename (config_dir, SESSION_CONFIG_FILENAME, NULL); if (!g_file_test(config_dir, G_FILE_TEST_IS_DIR) || !g_file_test(config_file, G_FILE_TEST_IS_REGULAR)) { if (create_new() < 0) { applet_exit(-1); } } applet_log_init(config_dir); applet_message ("Load config dir %s success\n", config_dir); applet_message ("starting seafile-applet "PACKAGE_VERSION"\n"); g_setenv("CCNET_CONF_DIR", config_dir, 1); g_free (config_file); }
int dfs_open(struct file *filp, char *name, int mode) { struct filsys *fs; struct inode *inode; int len; fs = (struct filsys *) filp->fs->data; len = strlen(name); switch (filp->flags & (VFS_O_CREAT | VFS_O_EXCL | VFS_O_TRUNC | VFS_O_SPECIAL)) { case 0: case VFS_O_EXCL: // Open existing file inode = open_existing(fs, name, len); break; case VFS_O_CREAT: // Open file, create new file if it does not exists inode = open_always(fs, name, len, mode); break; case VFS_O_CREAT | VFS_O_EXCL: case VFS_O_CREAT | VFS_O_TRUNC | VFS_O_EXCL: // Create new file, unlink existing file if it exists inode = create_new(fs, name, len, mode); break; case VFS_O_TRUNC: case VFS_O_TRUNC | VFS_O_EXCL: // Open and truncate existing file inode = truncate_existing(fs, name, len); filp->flags |= F_MODIFIED; break; case VFS_O_CREAT | VFS_O_TRUNC: // Create new file, fail if it exists inode = create_always(fs, name, len, -1, mode); break; case VFS_O_SPECIAL: // Create new file with special inode number inode = create_always(fs, name, len, filp->flags >> 24, mode); break; default: return -1; } if (!inode) return -1; if (filp->flags & VFS_O_APPEND) filp->pos = (int) inode->desc->size; filp->data = inode; return 0; }
sync_object *sync_object::childObject(const std::string &name) { if (!this->has_children()) { sync_object *rv = create_new(name); return rv; } for (std::map<uint, sync_object *>::iterator it = p_object->m_child_map.begin(); it != p_object->m_child_map.end(); ++it) { if (!it->second) continue; if (it->second->name() == name) { return it->second; } } return 0; }
int main(int agv,char *agc[]) { char lstname[256],dataname[256]; if (agv==1) { printf("Need Argument\n"); return -1; } if (agc[1][0]=='x') { char filename[256]; int i; strcpy(lstname,agc[2]); strcpy(dataname,agc[2]); strcat(lstname,".lst"); strcat(dataname,".wdf"); if (!file_exist(lstname)) { printf("Can't open list file[.lst]\n"); return -1; } if (!file_exist(dataname)) { printf("Can't open data file[.wdf]\n"); return -1; } _mkdir(agc[2]); FileList list; int n; n=list.ReadListOnly(lstname); std::vector<FILE_LST> old_list; int old_number=read_lst(dataname,old_list); FILE *df; df=fopen(dataname,"rb"); for (i=0;i<n;i++) { FILE *f; int j; static char buffer[1024]; strcpy(filename,agc[2]); strcat(filename,"\\"); int n; n=list.IsFileExist(i,old_list,old_number); printf("%s [%x] ",list.GetName(i),list.GetID(i)); if (n<0) { printf(" Can't find\n"); continue; } strcat(filename,list.GetName(i)); char *path=strchr(filename,'\\'); path=strchr(path+1,'\\'); if (path) { path[0]=0; _mkdir(filename); path[0]='\\'; } f=fopen(filename,"wb"); fseek(df,old_list[n].offset,SEEK_SET); for (j=0;j<old_list[n].size-1024;j+=1024) { fread(buffer,1,1024,df); fwrite(buffer,1,1024,f); } j=old_list[n].size-j; fread(buffer,1,j,df); fwrite(buffer,1,j,f); fclose(f); printf(" Extracted\n"); } fclose(df); return 0; } strcpy(lstname,agc[1]); strcpy(dataname,agc[1]); strcat(lstname,".lst"); strcat(dataname,".wdf"); if (!file_exist(lstname)) { printf("Can't open list file[.lst]\n"); return -1; } if (file_exist(dataname)) { printf("Updating Data File...\n"); update_datafile(dataname,lstname); } else { printf("Creating New Data File...\n"); create_new(dataname,lstname); } return 0; }