Fallback readdir_r().

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@1737 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
meep-eep
2005-05-11 10:33:55 +00:00
parent 33752ac2e8
commit 4d4f59e614
2 changed files with 36 additions and 0 deletions
+31
View File
@@ -21,8 +21,12 @@
*/ */
#include <ctype.h> #include <ctype.h>
#include "errno.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#ifndef HAVE_READDIR_R
# include <dirent.h>
#endif
#include "port.h" #include "port.h"
#ifndef HAVE_STRUPR #ifndef HAVE_STRUPR
@@ -78,4 +82,31 @@ setenv (const char *name, const char *value, int overwrite)
} }
#endif #endif
#ifndef HAVE_READDIR_R
// NB. This function calls readdir() directly, and as such has the same
// reentrance issues as that function. For the purposes of UQM it will
// do though.
// Note the POSIX requires that "The pointer returned by readdir()
// points to data which may be overwritten by another call to
// readdir( ) on the same directory stream. This data is not
// overwritten by another call to readdir() on a different directory
// stream."
// NB. This function makes an extra copy of the dirent and will hence be
// slower than a direct call to readdir() or readdir_r().
int
readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result) {
struct dirent *readdir_entry;
readdir_entry = readdir(dirp);
if (readdir_entry == NULL) {
*result = NULL;
return errno;
}
*entry = *readdir_entry;
*result = entry;
return 0;
}
#endif
+5
View File
@@ -19,6 +19,11 @@
char *strupr (char *str); char *strupr (char *str);
#endif #endif
#ifndef HAVE_READDIR_R
# include <dirent.h>
int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result);
#endif
// Compilation related // Compilation related
#ifdef _MSC_VER #ifdef _MSC_VER