[bug][fix] platform/unix/directory.c doesn't compile under Debian
Linux
Tim Olson
tim at io.com
Sat Nov 13 05:53:49 PST 2004
There are variable declarations in readDirectory() which are not at
the beginning of a block; that is illegal in ANSI C (dunno why it
compiles OK under MacOS, which is also using gcc)?
Here is a modified version which fixes this:
=====
int readDirectory(int dirHandle, struct ByteArray *entNameBuffer) {
struct dirent ent;
struct dirent *result = &ent;
int resultCode, entLen;
if (dirHandle < 0)
return -EINVAL;
#ifdef __CYGWIN__
result = readdir(dirs[dirHandle]);
resultCode = errno;
#else
resultCode = readdir_r(dirs[dirHandle], result, &result);
#endif
if (resultCode != 0) {
/* An error situation. */
assert(resultCode >= 0); /* TODO: read SUSv2. The Darwin manpage
is unclear about this */
return -resultCode;
}
if (result == NULL) {
/* End of the directory. */
return 0;
}
entLen = strlen(result->d_name);
if (entLen == 0) {
/* Bizarre! Make up a reasonable response. */
return -ENOENT;
}
assert(BYTEARRAY_LEN(entNameBuffer) >= entLen);
memcpy(entNameBuffer->elements, result->d_name, entLen);
return entLen;
}
=====
More information about the Slate
mailing list