2 * (c) The University of Glasgow 2002
4 * Directory Runtime Support
7 /* needed only for solaris2_HOST_OS */
10 // The following is required on Solaris to force the POSIX versions of
11 // the various _r functions instead of the Solaris versions.
12 #ifdef solaris2_HOST_OS
13 #define _POSIX_PTHREAD_SEMANTICS
18 #if defined(_MSC_VER) || defined(__MINGW32__) || defined(_WIN32)
24 * read an entry from the directory stream; opt for the
25 * re-entrant friendly way of doing this, if available.
28 __hscore_readdir( DIR *dirPtr, struct dirent **pDirEnt )
33 static unsigned int nm_max = (unsigned int)-1;
35 if (pDirEnt == NULL) {
38 if (nm_max == (unsigned int)-1) {
40 nm_max = NAME_MAX + 1;
42 nm_max = pathconf(".", _PC_NAME_MAX);
43 if (nm_max == -1) { nm_max = 255; }
47 p = (struct dirent*)malloc(sizeof(struct dirent) + nm_max);
48 if (p == NULL) return -1;
49 res = readdir_r(dirPtr, p, pDirEnt);
54 else if (*pDirEnt == NULL) {
61 if (pDirEnt == NULL) {
65 *pDirEnt = readdir(dirPtr);
66 if (*pDirEnt == NULL) {
75 * Function: __hscore_renameFile()
77 * Provide Haskell98's semantics for renaming files and directories.
78 * It mirrors that of POSIX.1's behaviour for rename() by overwriting
79 * the target if it exists (the MS CRT implementation of rename() returns
84 __hscore_renameFile( char *src, char *dest)
86 #if defined(_MSC_VER) || defined(__MINGW32__) || defined(_WIN32)
87 static int forNT = -1;
89 /* ToDo: propagate error codes back */
90 if (MoveFileA(src, dest)) {
96 /* Failed...it could be because the target already existed. */
97 if ( !GetFileAttributes(dest) ) {
98 /* No, it's not there - just fail. */
105 ovi.dwOSVersionInfoSize = sizeof(ovi);
106 if ( !GetVersionEx(&ovi) ) {
110 forNT = ((ovi.dwPlatformId & VER_PLATFORM_WIN32_NT) != 0);
114 /* Easy, go for MoveFileEx() */
115 if ( MoveFileExA(src, dest, MOVEFILE_REPLACE_EXISTING) ) {
123 /* No MoveFileEx() for Win9x, try deleting the target. */
124 /* Similarly, if the MoveFile*() ops didn't work out under NT */
125 if (DeleteFileA(dest)) {
126 if (MoveFileA(src,dest)) {
137 return rename(src,dest);