|
From: Keith M. <kei...@us...> - 2015-02-07 06:13:17
|
On 06/02/15 18:08, Miro Kropáček wrote: > Well, it's not my project, it's someone else's. It's used like this: > > #define DIRHANDLE dirp->dd_handle > > DIR *dirp; > > if ((dirp = opendir(dirname)) == NULL) > return(-1); > > if (fstat(DIRHANDLE, &stb) < 0) > return(-1); > > Not saying it's a great practice, though. So I'd like to make it compilable > somehow, it works for other Unix flavors, incl. Cygwin. Really? You amaze me. Can you name any such Unix flavours? (FWIW, GNU/Linux certainly isn't among them). I see two fatally flawed assumptions in the above code snippet: 1) It assumes that the opaque entity referenced by dirp represents a struct or a union, which includes a dd_handle member; there is no way in which you can be certain of that. 2) Even if (1) were true, it assumes that this dd_handle member is a descriptor reference to a file stream; on Windows, it is impossible to process a directory as a regular file stream, (notwithstanding the hoops cygwin may jump through, to make it appear otherwise). Like Eli says, your code snippet is not portable; in fact, it is just plain broken. -- Regards, Keith. |