c - maximum number of files/directories handled by dirent struct -


i have directory (let's call directory a) contains ~15000 directories (b1,b2,..,b15000), each directory of b's includes file(let's call "raw") want read. want read: a/b1/raw a/b2/raw ...

i don't know b's directories names in advance, know name of directory , each b's directory there file called raw.

so used dirent in order opendir , move on directories in - extracting name contained in d_name field, run stopped after read names of 264 directories!!

i wonder if struct dirent cannot hold more 264 directories ? can me ?

thanks in advanced.


[code comment]

dir* droot = opendir(argv[1]); assert(droot != null); struct dirent* dir;  while((dir = readdir(droot))) {     //suppose dirname string "argv[1]/dir->d_name/raw"     file* file = fopen(dirname,"r");      //do      fclose(file); }  closedir(droot); 

readdir() allocates memory every struct dirent returns pointer to. dirents deallocated automatically on closedir(), can't free() memory when no longer need particular dirent, , can't use dirent after closedir(). suppose it's possible (though not likely) program can't allocate more memory dirents.
you check errno after readdir() returns null find out.

if problem, can instead use readdir_r(), uses dirent* allocation provide (which local variable on stack), , reuse dirents, 1 after other. 1 caveat readdir_r() size of struct dirent depends on file system, , need ensure allocation big enough.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -