void hashtable_install( obj table, obj hash, obj key, obj value ) { obj vec, bucket; UINT_32 i; inserting_one( table ); vec = gvec_read( table, HASHTABLE_DIRECTORY ); for (bucket = read_dir(vec,hash); !EQ(bucket,FALSE_OBJ); bucket = gvec_read( bucket, BUCKET_OVERFLOW )) { for (i=SLOT(2); i<SLOT(2+BUCKET_CAPACITY); i+=sizeof(obj)) { if (EQ(read_bucket_hash(bucket,i),FALSE_OBJ)) { write_bucket_hash( bucket, i, hash ); write_bucket_key( bucket, i, key ); write_bucket_value( bucket, i, value ); return; } } } /* grow things... */ split_bucket( table, read_dir( vec, hash ), hash, key, value ); }
void * load_images(void * arg) { const char * directory = (const char *)arg; read_dir(directory, count_images); if (total_images_count > 0) { images_info = safe_malloc((total_images_count) * sizeof(image_info)); images = safe_malloc((total_images_count) * sizeof(bmp)); read_dir(directory, load_image); } return NULL; }
bool try_dir_lookup(inode* dir, std::string const& name, uint32_t& ino) { if (!dir) throw std::invalid_argument("dir_lookup null arg: dir"); // If our path resolution code works as expected, the filename // of any path will never be 0 bytes in length. So an assert is fine. assert(name.size() > 0); if (name.size() > MAX_FILENAME_LEN) throw fs_error(ERROR_NAMETOOLONG); inode_guard lock(dir->lock); auto entries = read_dir(dir); for (auto& j : entries) { if (!compare_dirent_name(j, name)) continue; ino = j.f_ino; return true; } return false; }
int MAIN(ls, int argc, char** argv) { if(getcwd(path, sizeof(path)) == 0) { printf("errors in getcwd\n"); return 1; } int fd = open(path, 0); if(fd < 0) { printf("cannot open file or directory\n"); return 1; } char buffer[256]; fnode_t *dir; while((dir = read_dir(fd, buffer, sizeof(buffer)))) { if(dir->flags & DIRENT_DIR) printf("\e[01;34m"); printf("%s", buffer); printf("\e[00m\n"); free(dir); } close(fd); return 0; }
void dir_unlink(inode* inode, std::string const& name) { if (!inode) throw std::invalid_argument("dir_unlink null arg: inode"); // If our path resolution code works as expected, the filename // of any path will never be 0 bytes in length. So an assert is fine. assert(name.size() > 0); if (name.size() > MAX_FILENAME_LEN) throw fs_error(ERROR_NAMETOOLONG); inode_guard lock(inode->lock); auto entries = read_dir(inode); for (auto it = entries.begin(); it != entries.end(); ++it) { if (!compare_dirent_name(*it, name)) continue; entries.erase(it); write_dir(inode, entries); return; } throw fs_error(ERROR_NOENTRY); }
int main(int argc, char** argv) { SDL_Surface* screen = NULL; if (!fatInitDefault()) { fprintf(stderr, "fatInitDefault failure: terminating\n"); exit(EXIT_FAILURE); } read_dir(); srand(time(NULL)); if (SDL_Init(SDL_INIT_VIDEO) < 0) { fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError()); exit(EXIT_FAILURE); } fontmap_init(); WPAD_Init(); SDL_WM_SetCaption("304pacman", NULL); atexit(SDL_Quit); SDL_ShowCursor(SDL_DISABLE); screen = SDL_SetVideoMode(640, 480, 8, SDL_HWSURFACE); if (!screen) { fprintf(stderr, "Unable to set video: %s\n", SDL_GetError()); exit(EXIT_FAILURE); } play(screen); SDL_Quit(); return (EXIT_SUCCESS); }
JNIEXPORT jlong JNICALL Java_com_sun_management_UnixOperatingSystem_getOpenFileDescriptorCount (JNIEnv *env, jobject mbean) { DIR *dirp; struct dirent dbuf; struct dirent* dentp; jlong fds = 0; dirp = opendir("/proc/self/fd"); if (dirp == NULL) { throw_internal_error(env, "Unable to open directory /proc/self/fd"); return -1; } // iterate through directory entries, skipping '.' and '..' // each entry represents an open file descriptor. while ((dentp = read_dir(dirp, &dbuf)) != NULL) { if (isdigit(dentp->d_name[0])) { fds++; } } closedir(dirp); // subtract by 1 which was the fd open for this implementation return (fds - 1); }
void dir_link(inode* inode, std::string const& name, uint32_t ino) { assert(inode); // If our path resolution code works as expected, the filename // of any path will never be 0 bytes in length. So an assert is fine. assert(name.size() > 0); if (name.size() > MAX_FILENAME_LEN) throw fs_error(ERROR_NAMETOOLONG); dir_entry ent; ent.f_ino = ino; if (0 < name.size()) { ent.f_namelen = (uint8_t) name.size(); std::memcpy(ent.f_name, name.c_str(), name.size()); } inode_guard lock(inode->lock); auto entries = read_dir(inode); for (auto& j : entries) { if (!compare_dirent_name(j, name)) continue; throw fs_error(ERROR_EXIST); } entries.emplace_back(ent); write_dir(inode, entries); }
/* Auslesen der Minimal- und Maximalwerte der in den Trajektoriendateien * enthaltenen Aufpunkte in Laengen- und Breitengrad (lo_min, la_min, * lo_max, la_max) */ void get_lo_la_min_max(struct state* state) { int i; /* Initialisieren */ state->lo_min = 2; state->la_min = 2; state->lo_max = -2; state->la_max = -2; /* Auslesen der Dateinamen der im angegebenen Verzeichnis enthaltenen * Dateien und Speicherung in einer Dateinamenliste (list) */ read_dir(get_string(INPUTDIR), state->list, state->list_max); /* Durchsuchen der in der Liste enthaltenen Trajektoriendateien nach * den groessten und kleinsten Koordinaten (lo_min, la_min, lo_max, * la_max) */ for (i = 0; i < state->list_max; i++) file_la_lo_min_max(state->list[i], &state->lo_min, &state->la_min, &state->lo_max, &state->la_max); /* Umrechnen der Minimal- und Maximalkoordinaten von Rad in Grad */ state->lo_min = rad2deg(state->lo_min); state->la_min = rad2deg(state->la_min); state->lo_max = rad2deg(state->lo_max); state->la_max = rad2deg(state->la_max); }
CL_FileDialog_Generic::CL_FileDialog_Generic( CL_FileDialog *self, const std::string &title, const std::string &file, const std::string &filter) : filedialog(self) { behavior = CL_FileDialog::quit_always; button = CL_FileDialog::button_none; // TODO: Calculate proper size int width = 400; int height = 315; int x = (CL_Display::get_width() - width) / 2; int y = (CL_Display::get_height() - height) / 2; filedialog->set_position(CL_Rect(x, y, x + width, y + height)); filedialog->set_title(title); CL_Component *client_area = filedialog->get_client_area(); width = client_area->get_width(); label_dir = new CL_Label(CL_Point(10, 12), "Directory:", client_area); input_dir = new CL_InputBox(CL_Rect(65, 10, width - 120, 30), client_area); input_dir->enable(false); button_parent = new CL_Button(CL_Rect(width - 115, 9, width - 65, 28), "Parent", client_area); button_createdir = new CL_Button(CL_Rect(width - 60, 9, width - 10, 28), "New", client_area); treeview_files = new CL_TreeView(CL_Rect(10, 32, width - 10, 197), client_area); treeview_files->add_column("Filename", 200); treeview_files->add_column("Size", 80); treeview_files->add_column("Type", 100); treeview_files->show_root_decoration(false); label_file = new CL_Label(CL_Point(10, 207), "Filename:", client_area); input_file = new CL_InputBox(CL_Rect(65, 205, width - 10, 225), client_area); label_filter = new CL_Label(CL_Point(10, 232), "Filter:", client_area); input_filter = new CL_InputBox(CL_Rect(65, 230, width - 10, 250), client_area); button_ok = new CL_Button(CL_Rect(10, 260, 100, 280), "OK", client_area); button_cancel = new CL_Button(CL_Rect(width - 110, 260, width - 10, 280), "Cancel", client_area); slots.connect(self->sig_set_options(), this, &CL_FileDialog_Generic::on_set_options); slots.connect(treeview_files->sig_selection_changed(), this, &CL_FileDialog_Generic::on_file_activated); slots.connect(button_ok->sig_clicked(), this, &CL_FileDialog_Generic::on_button_quit, true); slots.connect(button_cancel->sig_clicked(), this, &CL_FileDialog_Generic::on_button_quit, false); slots.connect(button_parent->sig_clicked(), this, &CL_FileDialog_Generic::on_button_parent); slots.connect(button_createdir->sig_clicked(), this, &CL_FileDialog_Generic::on_button_createdir); slots.connect(input_file->sig_return_pressed(), this, &CL_FileDialog_Generic::on_edit_file); slots.connect(input_filter->sig_return_pressed(), this, &CL_FileDialog_Generic::on_edit_filter); slots.connect(input_dir->sig_return_pressed(), this, &CL_FileDialog_Generic::on_edit_dir); set_file(file, false); set_filter(filter, false); show_hidden = false; read_dir(); }
void listdir(char *d, FILE *fp) { char path[512], rpath[512]; #if 0 long pathsize = 0; #endif struct _info **dir, **sav; int n, i; char *s; static char *igdir[] = { "/nfs", "/dev", "/proc", "/opt", "/tmp", "/etc", "nfs", "dev", "proc", "opt", "tmp", "etc", NULL }; sav = dir = read_dir(d, &n); if (!dir && n) Err("Dir read"); if (!n) { free_dir(sav); return; } qsort(dir, n, sizeof(struct _info *), cmpfunc); for(i = 0;i < n;++i) { #if 0 if (sizeof(char) * (strlen(d)+strlen(dir[i]->name) + 2) > pathsize) path = xrealloc(path,pathsize=(sizeof(char) * (strlen(d)+strlen(dir[i]->name) + 1024))); #endif if (!strncmp(d, "/", 1)) s = d + 1; else if (!strncmp(d, "./", 2)) s = d + 2; else s = d; sprintf(path,"%s/%s", s, dir[i]->name); sprintf(rpath,"%s/%s", d, dir[i]->name); if (dir[i]->isdir) { int j; int flg = 1; for(j = 0;igdir[j] != NULL;++j) { if (!strcmp(path, igdir[j])) { flg = 0; break; } } // if (flg) listdir(rpath, fp); } else { if (dir[i]->lnk == NULL) { // printf("delete %s\n", rpath); crstrip(rpath); } } } // free(path); free_dir(sav); }
void list_files(AMDeviceRef device) { service_conn_t houseFd = start_house_arrest_service(device); afc_connection afc_conn; afc_connection* afc_conn_p = &afc_conn; AFCConnectionOpen(houseFd, 0, &afc_conn_p); read_dir(houseFd, afc_conn_p, "/"); }
bool is_dir_empty(inode* dir) { if (!dir) throw std::invalid_argument("is_dir_empty null arg: dir"); inode_guard lock(dir->lock); auto content = read_dir(dir); return content.empty(); }
int main(int argc, char *argv[]) { if (argc!=3) { fprintf(stderr,"Usage: %s hostname dir\n",argv[0]); exit(0); } char dir[DIR_SIZE]; strcpy(dir, argv[2]); read_dir(argv[1], dir); printf("%s\n", dir); exit(0); }
int run_dbcheck() { int i = 0; __counter = 0; while (syscheck.dir[i] != NULL) { read_dir(syscheck.dir[i], syscheck.opts[i], syscheck.filerestrict[i]); i++; } return (0); }
int main(int argc, char *argv[]) { char *path; if(argc>1){ path = argv[1]; // dir = opendir(argv[1]); /*your directory*/ } else { path = "."; // dir = opendir("."); /* Default: current path */ } return read_dir(path); }
void CL_FileDialog_Generic::on_set_options(const CL_DomElement &options) { if (options.has_attribute("file")) set_file(options.get_attribute("file"), false); if (options.has_attribute("filter")) set_filter(options.get_attribute("filter"), false); if (options.has_attribute("show_hidden")) show_hidden = CL_String::to_bool(options.get_attribute("show_hidden")); read_dir(); }
READDIR3res *nfsproc3_readdir_3_svc(READDIR3args * argp, struct svc_req * rqstp) { static READDIR3res result; char *path; PREP(path, argp->dir); result = read_dir(path, argp->cookie, argp->cookieverf, argp->count); result.READDIR3res_u.resok.dir_attributes = get_post_stat(path, rqstp); return &result; }
void iterate_dir(inode* dir, void* pdata, iterate_dir_callback cb) { if (!dir) throw std::invalid_argument("iterate_dir invalid arg: dir"); inode_guard lock(dir->lock); auto entries = read_dir(dir); for (auto& j : entries) { std::string name(j.f_name, j.f_namelen); cb(pdata, j.f_ino, name); } }
/* * calculate size of database in all tablespaces */ static int64 calculate_database_size(oid_t dbOid) { int64 totalsize; DIR *dirdesc; struct dirent *direntry; char dirpath[MAX_PG_PATH]; char pathname[MAX_PG_PATH]; acl_result_e aclresult; /* User must have connect privilege for target database */ aclresult = db_acl_check(dbOid, get_uid(), ACL_CONNECT); if (aclresult != ACLCHECK_OK) aclcheck_error(aclresult, ACL_KIND_DATABASE, get_db_name(dbOid)); /* Shared storage in pg_global is not counted */ /* Include pg_default storage */ snprintf(pathname, MAX_PG_PATH, "base/%u", dbOid); totalsize = db_dir_size(pathname); /* scan_pl the non-default tablespaces */ snprintf(dirpath, MAX_PG_PATH, "pg_tblspc"); dirdesc = alloc_dir(dirpath); if (!dirdesc) ereport(ERROR, (errcode_file_access(), errmsg("could not open tablespace directory \"%s\": %m", dirpath))); while ((direntry = read_dir(dirdesc, dirpath)) != NULL) { CHECK_FOR_INTERRUPTS(); if (strcmp(direntry->d_name, ".") == 0 || strcmp(direntry->d_name, "..") == 0) continue; snprintf(pathname, MAX_PG_PATH, "pg_tblspc/%s/%s/%u", direntry->d_name, TBS_VERSION_DIR, dbOid); totalsize += db_dir_size(pathname); } free_dir(dirdesc); /* Complain if we found no trace of the DB at all */ if (!totalsize) ereport(ERROR, (E_UNDEFINED_DATABASE, errmsg("database with OID %u does not exist", dbOid))); return totalsize; }
int main(int argc, char **argv) { int n; char **in; char *path; option_parse(argc, argv); agurim_init(); argc -= optind; argv += optind; if (argc == 0){ /* stdin supports re-aggregation format only. */ if (query.outfmt != REAGGREGATION) usage(); else read_stdin(); } again: n = argc; in = argv; while (n > 0) { path = *in; if (is_dir(path)) read_dir(path); else read_file(path); ++in; --n; } if (inparam.mode == HHH_MAIN_MODE){ hhh_run(); if (query.outfmt != REAGGREGATION) { /* reset internal parameters for text processing */ param_set_nextmode(); /* goto the second pass */ goto again; } } else { plot_run(); } agurim_finish(); return (0); }
int sys_dirstat(char *dir, unsigned num, char *namebuf, struct stat *statbuf) { if(!namebuf || !statbuf || !dir) return -EINVAL; struct inode *i = read_dir(dir, num); if(!i) return -ESRCH; do_stat(i, statbuf); strncpy(namebuf, i->name, 128); if(i->dynamic) { rwlock_acquire(&i->rwl, RWL_WRITER); free_inode(i, 0); } return 0; }
void CL_FileDialog_Generic::on_file_activated(const CL_TreeNode &node) { CL_TreeItem *treeitem = (CL_TreeItem *)node.get_component(); std::string item = treeitem->get_text(0); if(treeitem->get_text(2) == "Directory") { CL_Directory::change_to(item); read_dir(); } else { set_file(item, false); } }
void IdentifyChromosomes(const string& chrom_file, vector<string>& chrom_files) { fprintf(stderr, "[IDENTIFYING CHROMS] "); if (isdir(chrom_file.c_str())) { read_dir(chrom_file, "fa", chrom_files); } else { chrom_files.push_back(chrom_file); } fprintf(stderr, "[DONE]\n"); fprintf(stderr, "chromosome files found (approx size):\n"); for (uint32_t i = 0; i < chrom_files.size(); ++i) { fprintf(stderr, "%s (%.2lfMbp)\n", chrom_files[i].c_str(), roundf(get_filesize(chrom_files[i]) / 1e06)); } }
void *musicplay(void *arg) { int i ,count; char mp3_file[10][40]; char command[30]; printf("enter musicplay\n"); count = read_dir("/mp3",".mp3",&mp3_file); printf(" read mp3 file ret = %d \n",count); for(i=0;i<count;i++) { sprintf(command,"madplay %s\n",mp3_file[i]); system(command); } pthread_exit("play music is done"); }
int main(int argc, char **argv) { const char *root_dir; DIR *dir; if (argc < 3) { fprintf(stderr, "usage: %s <size> <root_dir>\n", argv[0]); return 1; } image_size = atoi(argv[1]); if (image_size == 0) { fprintf(stderr, "invalid size '%s'\n", argv[1]); return 1; } root_dir = argv[2]; image = malloc(image_size); if (image == NULL) { fprintf(stderr, "cannot allocate %lu bytes\n", image_size); return 1; } mem_spiffs_erase(0, image_size); mem_spiffs_mount(); // Will fail but is required. SPIFFS_format(&fs); if (mem_spiffs_mount() != SPIFFS_OK) { fprintf(stderr, "SPIFFS_mount failed: %d\n", SPIFFS_errno(&fs)); return 1; } fprintf(stderr, "adding files in directory %s\n", root_dir); if ((dir = opendir(root_dir)) == NULL) { fprintf(stderr, "unable to open directory %s\n", root_dir); return 1; } else { read_dir(dir, root_dir); } fwrite(image, image_size, 1, stdout); u32_t total, used; SPIFFS_info(&fs, &total, &used); fprintf(stderr, "Image stats: size=%u, space: total=%u, used=%u, free=%u\n", (unsigned int) image_size, total, used, total - used); return 0; }
void read_dir(service_conn_t afcFd, afc_connection* afc_conn_p, const char* dir) { char *dir_ent; afc_connection afc_conn; if (!afc_conn_p) { afc_conn_p = &afc_conn; AFCConnectionOpen(afcFd, 0, &afc_conn_p); } printf("%s\n", dir); afc_dictionary afc_dict; afc_dictionary* afc_dict_p = &afc_dict; AFCFileInfoOpen(afc_conn_p, dir, &afc_dict_p); afc_directory afc_dir; afc_directory* afc_dir_p = &afc_dir; afc_error_t err = AFCDirectoryOpen(afc_conn_p, dir, &afc_dir_p); if (err != 0) { // Couldn't open dir - was probably a file return; } while(true) { err = AFCDirectoryRead(afc_conn_p, afc_dir_p, &dir_ent); if (!dir_ent) break; if (strcmp(dir_ent, ".") == 0 || strcmp(dir_ent, "..") == 0) continue; char* dir_joined = malloc(strlen(dir) + strlen(dir_ent) + 2); strcpy(dir_joined, dir); if (dir_joined[strlen(dir)-1] != '/') strcat(dir_joined, "/"); strcat(dir_joined, dir_ent); read_dir(afcFd, afc_conn_p, dir_joined); free(dir_joined); } AFCDirectoryClose(afc_conn_p, afc_dir_p); }
int main() { BLOCK_DEVICE *device; FSFILE *file; unsigned char i; unsigned long filepos; /* avoid issues with the interrupt routine hijacking the IY register - not sure how big a problem this really is, but can't hurt... */ #asm di #endasm buffer_emptybuffers(); // TODO: Can this be sensibly incorporated into fatfs_init? printf("Initializing fatfs library\n"); fatfs_init(); printf("opening DivIDE master drive\n"); device = divide_open_drive(DIVIDE_DRIVE_MASTER); printf("opening FATfs filesystem on it\n"); fatfs_fsopen(device, &fs); printf("fatfs filesystem at %04x\n", &fs); open_root_dir(&fs, &dir); printf("dir handle at %04x\n", &dir); for (i = 0; i < 13; i++) { read_dir(&dir, &entry); /* printf("%s\n", entry.filename); */ } printf("dirent at %04x\n", &entry); file = open_dirent(&entry, FILE_MODE_EXC_READ); printf("file handle at %04x\n", file); read_file(file, buffer1, 5); printf("first 5 chars stored at %04x\n", buffer1); seek_file(file, 2L); read_file(file, buffer2, 5); printf("chars 2-6 stored at %04x\n", buffer2); i = read_byte(file); printf("char 7 is %02x\n", i); filepos = get_file_pos(file); printf("file position is now %08lx\n", filepos); close_file(file); #asm ei #endasm return 0; }
void eachitem(void (*emit)(char*), int all, int update) { int i; read_dir(update); for(i=0; i<n_count; i++) { if(n_list[i].name[0] == 0) { /* newstime */ if(all) continue; break; } if(n_list[i].length == 0) /* in progress */ continue; (*emit)(n_list[i].name); } }
static int rdp (int argc, char *argv[]) { static dir_s dir; unsigned i; int rc; u64 ino; for (i = 1; i < argc; i++) { ino = atoll(argv[i]); if (ino) { rc = read_dir(ino, &dir); if (rc) return rc; pr_dir( &dir); } } return 0; }