Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I'm not sure how FindFirstFile/FindNextFile is going to be better than readdir(3) on Unix.

At the NT layer, beneath FindFirstFile/FindNextFile, there is a call that says "fill this buffer with directory entry metadata." - https://docs.microsoft.com/en-us/windows/desktop/devnotes/nt... - I know FindFirstFileEx for example can let you ask for a larger buffer size to pass to that layer, thereby reducing syscall overhead in a big directory.

If you look at getdirentries(2) on FreeBSD for example - https://www.freebsd.org/cgi/man.cgi?query=getdirentries - it's a very similar looking API. I thought I recall hearing that in the days before readdir(3) the traditional approach was to open(2) a dir and read(2) it, but I cannot find a source for that claim. At any rate you can imagine something pretty identical in the layer beneath readdir(3) on a modern Unix-like system and it being essentially the same as what Windows does.

I guess file size needs an extra stat(2) in Unix, since it is not in struct dirent, so if you do care about that or some of the other WIN32_FIND_DATA members the Windows way will be faster.



...but I cannot find a source for that claim.

You can see here that in UNIX v6 that /bin/ls had to implement its own readdir() function that calls fopen() on the directory and then getc() 16 times to read each 16-byte dirent:

https://github.com/yisooan/unix-v6/blob/2c7099ee501923775c4c...

You can also see that in those days, struct dirent contained only the inode and dname.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: