|
From: Keith M. <kei...@us...> - 2015-02-07 11:22:52
|
On 07/02/15 10:05, Miro Kropáček wrote: > http://sourceforge.net/p/aranym/code/ci/master/tree/src/gui-sdl/file.cpp#l63 > .. works on all Linuxes, FreeBSD, Solaris and Cygwin for good 10+ years. The fragment you showed most definitely does NOT compile on Linux; with the addition of a few necessary includes, and minimal infrastructure, on LinuxMint Debian this entirely equivalent fragment fails: $ cat foo.c #include <dirent.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #define DIRHANDLE dirp->dd_handle int main() { struct stat stb; DIR *dirp = opendir( "foodir" ); if( (dirp == NULL) || (fstat( DIRHANDLE, &stb ) < 0) ) return -1; return 0; } $ gcc -c -Wall foo.c foo.c: In function ‘main’: foo.c:6:23: error: dereferencing pointer to incomplete type #define DIRHANDLE dirp->dd_handle ^ foo.c:12:33: note: in expansion of macro ‘DIRHANDLE’ if( (dirp == NULL) || (fstat( DIRHANDLE, &stb ) < 0) ) > Via #ifdefs, but works. No doubt because the #ifdefs prevent the compiler from ever seeing the broken code fragment; IOW, that code specifically, does NOT work. > Guys, there's no need to show off... No one is showing off; merely stating the fact that the code you've shown is broken. In pure Windows code, compiled by MinGW -- because MSVC doesn't give you opendir() anyway -- the directory stream returned by opendir() is NOT a file stream. You cannot manipulate it using any function which requires a file descriptor argument. All you can be sure of is that you can retrieve struct dirent references from it, by calling readdir() to process it sequentially. Other than that, the only functions which can legitimately manipulate [*] it are telldir(), seekdir(), rewinddir(), and closedir() -- anything else is sure to result in failure. [*] Strictly, this same set of functions are the only ones which should be used on ANY platform, for this purpose; using anything else breaks portability, and should be considered a programming error. -- Regards, Keith. |