2 * (c) The University of Glasgow 2002
4 * Directory Runtime Support
7 /* needed only for solaris2_HOST_OS */
8 #ifdef __GLASGOW_HASKELL__
12 // The following is required on Solaris to force the POSIX versions of
13 // the various _r functions instead of the Solaris versions.
14 #ifdef solaris2_HOST_OS
15 #define _POSIX_PTHREAD_SEMANTICS
20 #if defined(_MSC_VER) || defined(__MINGW32__) || defined(_WIN32)
26 * read an entry from the directory stream; opt for the
27 * re-entrant friendly way of doing this, if available.
30 __hscore_readdir( DIR *dirPtr, struct dirent **pDirEnt )
35 static unsigned int nm_max = (unsigned int)-1;
37 if (pDirEnt == NULL) {
40 if (nm_max == (unsigned int)-1) {
42 nm_max = NAME_MAX + 1;
44 nm_max = pathconf(".", _PC_NAME_MAX);
45 if (nm_max == -1) { nm_max = 255; }
49 p = (struct dirent*)malloc(sizeof(struct dirent) + nm_max);
50 if (p == NULL) return -1;
51 res = readdir_r(dirPtr, p, pDirEnt);
56 else if (*pDirEnt == NULL) {
63 if (pDirEnt == NULL) {
67 *pDirEnt = readdir(dirPtr);
68 if (*pDirEnt == NULL) {