Sergei Gorelkin wrote:

It turns out that for longer filenames fpreaddir() failes with errno=22 (invalid argument).

Here is what I could find out:

In fpc, sizeof(dirent) is equal to 275, while gcc reports sizeof(dirent64)=276. Moreover, Linux kernel expects buffer for getdents64 syscall rounded up to 8 bytes (see fs/readdir.c in kernel source tree, macros ROUND_UP64 and NAME_OFFSET). Using these macros, we can calculate that for 255 char filename, a 280-byte buffer is expected (and value of 280 *is* returned in d_reclen field when filename length is 255). But that is still not working, for the reason I could not figure out. Only adding eight more bytes, i.e. using 288 bytes buffer, makes that syscall finally succeed with a 255 char filename.

A quick fix seems to just extend Dirent record with extra bytes, but perhaps there exists a more clean and consistent solution.

Best regards,
Sergei.
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply via email to