2 * (c) The University of Glasgow 2002
4 * Directory Runtime Support
9 // The following is required on Solaris to force the POSIX versions of
10 // the various _r functions instead of the Solaris versions.
11 #ifdef solaris2_TARGET_OS
12 #define _POSIX_PTHREAD_SEMANTICS
17 #if defined(mingw32_TARGET_OS)
22 * read an entry from the directory stream; opt for the
23 * re-entrant friendly way of doing this, if available.
26 __hscore_readdir( HsAddr dirPtr, HsAddr pDirEnt )
28 struct dirent **pDirE = (struct dirent**)pDirEnt;
32 static unsigned int nm_max = -1;
39 nm_max = NAME_MAX + 1;
41 nm_max = pathconf(".", _PC_NAME_MAX);
42 if (nm_max == -1) { nm_max = 255; }
46 p = (struct dirent*)malloc(sizeof(struct dirent) + nm_max);
47 if (p == NULL) return -1;
48 res = readdir_r((DIR*)dirPtr, p, pDirE);
60 *pDirE = readdir((DIR*)dirPtr);
70 * Function: __hscore_renameFile()
72 * Provide Haskell98's semantics for renaming files and directories.
73 * It mirrors that of POSIX.1's behaviour for rename() by overwriting
74 * the target if it exists (the MS CRT implementation of rename() returns
79 __hscore_renameFile( HsAddr src,
82 #if defined(_MSC_VER) || defined(_WIN32)
83 static int forNT = -1;
86 /* ToDo: propagate error codes back */
87 if (MoveFileA(src, dest)) {
93 /* Failed...it could be because the target already existed. */
94 if ( !GetFileAttributes(dest) ) {
95 /* No, it's not there - just fail. */
102 ovi.dwOSVersionInfoSize = sizeof(ovi);
103 if ( !GetVersionEx(&ovi) ) {
107 forNT = ((ovi.dwPlatformId & VER_PLATFORM_WIN32_NT) != 0);
111 /* Easy, go for MoveFileEx() */
112 if ( MoveFileExA(src, dest, MOVEFILE_REPLACE_EXISTING) ) {
120 /* No MoveFileEx() for Win9x, try deleting the target. */
121 /* Similarly, if the MoveFile*() ops didn't work out under NT */
122 if (DeleteFileA(dest)) {
123 if (MoveFileA(src,dest)) {
134 return rename(src,dest);