| OLD | NEW |
| 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
| 2 /* This Source Code Form is subject to the terms of the Mozilla Public | 2 /* This Source Code Form is subject to the terms of the Mozilla Public |
| 3 * License, v. 2.0. If a copy of the MPL was not distributed with this | 3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 5 | 5 |
| 6 /* Windows 95 IO module | 6 /* Windows 95 IO module |
| 7 * | 7 * |
| 8 * Assumes synchronous I/O. | 8 * Assumes synchronous I/O. |
| 9 * | 9 * |
| 10 */ | 10 */ |
| 11 | 11 |
| 12 #include "primpl.h" | 12 #include "primpl.h" |
| 13 #include <direct.h> | 13 #include <direct.h> |
| 14 #include <mbstring.h> | 14 #include <mbstring.h> |
| 15 #ifdef MOZ_UNICODE | 15 #ifdef MOZ_UNICODE |
| 16 #include <wchar.h> | 16 #include <wchar.h> |
| 17 #endif /* MOZ_UNICODE */ | 17 #endif /* MOZ_UNICODE */ |
| 18 | 18 |
| 19 #ifdef WINCE | |
| 20 | |
| 21 static HANDLE CreateFileA(LPCSTR lpFileName, | |
| 22 DWORD dwDesiredAccess, | |
| 23 DWORD dwShareMode, | |
| 24 LPSECURITY_ATTRIBUTES lpSecurityAttributes, | |
| 25 DWORD dwCreationDisposition, | |
| 26 DWORD dwFlagsAndAttributes, | |
| 27 HANDLE hTemplateFile) | |
| 28 { | |
| 29 PRUnichar wFileName[MAX_PATH]; | |
| 30 MultiByteToWideChar(CP_ACP, 0, lpFileName, -1, wFileName, MAX_PATH); | |
| 31 return CreateFileW(wFileName, dwDesiredAccess, dwShareMode, | |
| 32 lpSecurityAttributes, dwCreationDisposition, | |
| 33 dwFlagsAndAttributes, hTemplateFile); | |
| 34 } | |
| 35 | |
| 36 /* | |
| 37 * We seem to call FindFirstFileA and FindNextFileA just to get | |
| 38 * the file names in a directory listing. If so, we could define | |
| 39 * a custom WIN32_FIND_DATAA structure with just the cFileName | |
| 40 * member, and the CopyFindFileDataW2A function could just | |
| 41 * copy/convert the cFileName member. | |
| 42 */ | |
| 43 static void CopyFindFileDataW2A(LPWIN32_FIND_DATAW from, | |
| 44 LPWIN32_FIND_DATAA to) | |
| 45 { | |
| 46 /* | |
| 47 * WIN32_FIND_DATAA and WIN32_FIND_DATAW are slightly different. | |
| 48 * The dwReserved0, dwReserved1, and cAlternateFileName members | |
| 49 * exist only in WIN32_FIND_DATAA. The dwOID member exists only | |
| 50 * in WIN32_FIND_DATAW. | |
| 51 */ | |
| 52 to->dwFileAttributes = from->dwFileAttributes; | |
| 53 to->ftCreationTime = from->ftCreationTime; | |
| 54 to->ftLastAccessTime = from->ftLastAccessTime; | |
| 55 to->ftLastWriteTime = from->ftLastWriteTime; | |
| 56 to->nFileSizeHigh = from->nFileSizeHigh; | |
| 57 to->nFileSizeLow = from->nFileSizeLow; | |
| 58 to->dwReserved0 = 0; | |
| 59 to->dwReserved1 = 0; | |
| 60 WideCharToMultiByte(CP_ACP, 0, from->cFileName, -1, | |
| 61 to->cFileName, MAX_PATH, NULL, NULL); | |
| 62 to->cAlternateFileName[0] = '\0'; | |
| 63 } | |
| 64 | |
| 65 static HANDLE FindFirstFileA(LPCSTR lpFileName, | |
| 66 LPWIN32_FIND_DATAA lpFindFileData) | |
| 67 { | |
| 68 PRUnichar wFileName[MAX_PATH]; | |
| 69 HANDLE hFindFile; | |
| 70 WIN32_FIND_DATAW wFindFileData; | |
| 71 | |
| 72 MultiByteToWideChar(CP_ACP, 0, lpFileName, -1, wFileName, MAX_PATH); | |
| 73 hFindFile = FindFirstFileW(wFileName, &wFindFileData); | |
| 74 if (hFindFile != INVALID_HANDLE_VALUE) { | |
| 75 CopyFindFileDataW2A(&wFindFileData, lpFindFileData); | |
| 76 } | |
| 77 return hFindFile; | |
| 78 } | |
| 79 | |
| 80 static BOOL FindNextFileA(HANDLE hFindFile, | |
| 81 LPWIN32_FIND_DATAA lpFindFileData) | |
| 82 { | |
| 83 WIN32_FIND_DATAW wFindFileData; | |
| 84 BOOL rv; | |
| 85 | |
| 86 rv = FindNextFileW(hFindFile, &wFindFileData); | |
| 87 if (rv) { | |
| 88 CopyFindFileDataW2A(&wFindFileData, lpFindFileData); | |
| 89 } | |
| 90 return rv; | |
| 91 } | |
| 92 | |
| 93 static BOOL GetFileAttributesExA(LPCSTR lpFileName, | |
| 94 GET_FILEEX_INFO_LEVELS fInfoLevelId, | |
| 95 LPVOID lpFileInformation) | |
| 96 { | |
| 97 PRUnichar wFileName[MAX_PATH]; | |
| 98 MultiByteToWideChar(CP_ACP, 0, lpFileName, -1, wFileName, MAX_PATH); | |
| 99 return GetFileAttributesExW(wFileName, fInfoLevelId, lpFileInformation); | |
| 100 } | |
| 101 | |
| 102 static BOOL DeleteFileA(LPCSTR lpFileName) | |
| 103 { | |
| 104 PRUnichar wFileName[MAX_PATH]; | |
| 105 MultiByteToWideChar(CP_ACP, 0, lpFileName, -1, wFileName, MAX_PATH); | |
| 106 return DeleteFileW(wFileName); | |
| 107 } | |
| 108 | |
| 109 static BOOL MoveFileA(LPCSTR from, LPCSTR to) | |
| 110 { | |
| 111 PRUnichar wFrom[MAX_PATH]; | |
| 112 PRUnichar wTo[MAX_PATH]; | |
| 113 MultiByteToWideChar(CP_ACP, 0, from, -1, wFrom, MAX_PATH); | |
| 114 MultiByteToWideChar(CP_ACP, 0, to, -1, wTo, MAX_PATH); | |
| 115 return MoveFileW(wFrom, wTo); | |
| 116 } | |
| 117 | |
| 118 static BOOL CreateDirectoryA(LPCSTR lpPathName, | |
| 119 LPSECURITY_ATTRIBUTES lpSecurityAttributes) | |
| 120 { | |
| 121 PRUnichar wPathName[MAX_PATH]; | |
| 122 MultiByteToWideChar(CP_ACP, 0, lpPathName, -1, wPathName, MAX_PATH); | |
| 123 return CreateDirectoryW(wPathName, lpSecurityAttributes); | |
| 124 } | |
| 125 | |
| 126 static BOOL RemoveDirectoryA(LPCSTR lpPathName) | |
| 127 { | |
| 128 PRUnichar wPathName[MAX_PATH]; | |
| 129 MultiByteToWideChar(CP_ACP, 0, lpPathName, -1, wPathName, MAX_PATH); | |
| 130 return RemoveDirectoryW(wPathName); | |
| 131 } | |
| 132 | |
| 133 static long GetDriveType(const char *lpRootPathName) | |
| 134 { | |
| 135 PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0); | |
| 136 return 0; // The drive type cannot be determined. | |
| 137 } | |
| 138 | |
| 139 static DWORD GetFullPathName(const char *lpFileName, | |
| 140 DWORD nBufferLength, | |
| 141 const char *lpBuffer, | |
| 142 const char **lpFilePart) | |
| 143 { | |
| 144 // needs work dft | |
| 145 DWORD len = strlen(lpFileName); | |
| 146 if (len > nBufferLength) | |
| 147 return len; | |
| 148 | |
| 149 strncpy((char *)lpBuffer, lpFileName, len); | |
| 150 ((char *)lpBuffer)[len] = '\0'; | |
| 151 | |
| 152 if (lpFilePart) { | |
| 153 char *sep = strrchr(lpBuffer, '\\'); | |
| 154 if (sep) { | |
| 155 sep++; // pass the seperator | |
| 156 *lpFilePart = sep; | |
| 157 } else { | |
| 158 *lpFilePart = lpBuffer; | |
| 159 } | |
| 160 } | |
| 161 return len; | |
| 162 } | |
| 163 | |
| 164 static BOOL LockFile(HANDLE hFile, | |
| 165 DWORD dwFileOffsetLow, | |
| 166 DWORD dwFileOffsetHigh, | |
| 167 DWORD nNumberOfBytesToLockLow, | |
| 168 DWORD nNumberOfBytesToLockHigh) | |
| 169 { | |
| 170 OVERLAPPED overlapped = {0}; | |
| 171 overlapped.Offset = dwFileOffsetLow; | |
| 172 overlapped.OffsetHigh = dwFileOffsetHigh; | |
| 173 return LockFileEx(hFile, | |
| 174 LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, | |
| 175 0, // reserved | |
| 176 nNumberOfBytesToLockLow, | |
| 177 nNumberOfBytesToLockHigh, &overlapped); | |
| 178 } | |
| 179 | |
| 180 static BOOL UnlockFile(HANDLE hFile, | |
| 181 DWORD dwFileOffsetLow, | |
| 182 DWORD dwFileOffsetHigh, | |
| 183 DWORD nNumberOfBytesToUnlockLow, | |
| 184 DWORD nNumberOfBytesToUnlockHigh) | |
| 185 { | |
| 186 OVERLAPPED overlapped = {0}; | |
| 187 overlapped.Offset = dwFileOffsetLow; | |
| 188 overlapped.OffsetHigh = dwFileOffsetHigh; | |
| 189 return UnlockFileEx(hFile, | |
| 190 0, // reserved | |
| 191 nNumberOfBytesToUnlockLow, | |
| 192 nNumberOfBytesToUnlockHigh, &overlapped); | |
| 193 } | |
| 194 | |
| 195 static unsigned char *_mbsdec(const unsigned char *string1, | |
| 196 const unsigned char *string2) | |
| 197 { | |
| 198 // needs work dft | |
| 199 return NULL; | |
| 200 } | |
| 201 | |
| 202 static unsigned char *_mbsinc(const unsigned char *inCurrent) | |
| 203 { | |
| 204 // needs work dft | |
| 205 return (unsigned char *)(inCurrent + 1); | |
| 206 } | |
| 207 | |
| 208 #endif | |
| 209 | |
| 210 struct _MDLock _pr_ioq_lock; | 19 struct _MDLock _pr_ioq_lock; |
| 211 | 20 |
| 212 /* | 21 /* |
| 213 * NSPR-to-NT access right mapping table for files. | 22 * NSPR-to-NT access right mapping table for files. |
| 214 */ | 23 */ |
| 215 static DWORD fileAccessTable[] = { | 24 static DWORD fileAccessTable[] = { |
| 216 FILE_GENERIC_READ, | 25 FILE_GENERIC_READ, |
| 217 FILE_GENERIC_WRITE, | 26 FILE_GENERIC_WRITE, |
| 218 FILE_GENERIC_EXECUTE | 27 FILE_GENERIC_EXECUTE |
| 219 }; | 28 }; |
| 220 | 29 |
| 221 /* | 30 /* |
| 222 * NSPR-to-NT access right mapping table for directories. | 31 * NSPR-to-NT access right mapping table for directories. |
| 223 */ | 32 */ |
| 224 static DWORD dirAccessTable[] = { | 33 static DWORD dirAccessTable[] = { |
| 225 FILE_GENERIC_READ, | 34 FILE_GENERIC_READ, |
| 226 FILE_GENERIC_WRITE|FILE_DELETE_CHILD, | 35 FILE_GENERIC_WRITE|FILE_DELETE_CHILD, |
| 227 FILE_GENERIC_EXECUTE | 36 FILE_GENERIC_EXECUTE |
| 228 }; | 37 }; |
| 229 | 38 |
| 230 /* Windows CE has GetFileAttributesEx. */ | |
| 231 #ifndef WINCE | |
| 232 typedef BOOL (WINAPI *GetFileAttributesExFn)(LPCTSTR, | |
| 233 GET_FILEEX_INFO_LEVELS, | |
| 234 LPVOID); | |
| 235 static GetFileAttributesExFn getFileAttributesEx; | |
| 236 static void InitGetFileInfo(void); | |
| 237 #endif | |
| 238 | |
| 239 static void InitUnicodeSupport(void); | |
| 240 | |
| 241 static PRBool IsPrevCharSlash(const char *str, const char *current); | 39 static PRBool IsPrevCharSlash(const char *str, const char *current); |
| 242 | 40 |
| 243 void | 41 void |
| 244 _PR_MD_INIT_IO() | 42 _PR_MD_INIT_IO() |
| 245 { | 43 { |
| 246 WORD WSAVersion = 0x0101; | 44 WORD WSAVersion = 0x0101; |
| 247 WSADATA WSAData; | 45 WSADATA WSAData; |
| 248 int err; | 46 int err; |
| 249 | 47 |
| 250 err = WSAStartup( WSAVersion, &WSAData ); | 48 err = WSAStartup( WSAVersion, &WSAData ); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 270 systime.wMilliseconds = 0; | 68 systime.wMilliseconds = 0; |
| 271 | 69 |
| 272 rv = SystemTimeToFileTime(&systime, &filetime.ft); | 70 rv = SystemTimeToFileTime(&systime, &filetime.ft); |
| 273 PR_ASSERT(0 != rv); | 71 PR_ASSERT(0 != rv); |
| 274 PR_ASSERT(filetime.prt == _pr_filetime_offset); | 72 PR_ASSERT(filetime.prt == _pr_filetime_offset); |
| 275 } | 73 } |
| 276 #endif /* DEBUG */ | 74 #endif /* DEBUG */ |
| 277 | 75 |
| 278 _PR_NT_InitSids(); | 76 _PR_NT_InitSids(); |
| 279 | 77 |
| 280 #ifndef WINCE | |
| 281 InitGetFileInfo(); | |
| 282 #endif | |
| 283 | |
| 284 InitUnicodeSupport(); | |
| 285 | |
| 286 _PR_MD_InitSockets(); | 78 _PR_MD_InitSockets(); |
| 287 } | 79 } |
| 288 | 80 |
| 289 PRStatus | 81 PRStatus |
| 290 _PR_MD_WAIT(PRThread *thread, PRIntervalTime ticks) | 82 _PR_MD_WAIT(PRThread *thread, PRIntervalTime ticks) |
| 291 { | 83 { |
| 292 DWORD rv; | 84 DWORD rv; |
| 293 | 85 |
| 294 PRUint32 msecs = (ticks == PR_INTERVAL_NO_TIMEOUT) ? | 86 PRUint32 msecs = (ticks == PR_INTERVAL_NO_TIMEOUT) ? |
| 295 INFINITE : PR_IntervalToMilliseconds(ticks); | 87 INFINITE : PR_IntervalToMilliseconds(ticks); |
| (...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 788 * microseconds to milliseconds before doing the comparison. | 580 * microseconds to milliseconds before doing the comparison. |
| 789 */ | 581 */ |
| 790 PR_ASSERT((cmp / PR_USEC_PER_MSEC) == (*prtm / PR_USEC_PER_MSEC)); | 582 PR_ASSERT((cmp / PR_USEC_PER_MSEC) == (*prtm / PR_USEC_PER_MSEC)); |
| 791 } | 583 } |
| 792 #endif /* DEBUG */ | 584 #endif /* DEBUG */ |
| 793 } | 585 } |
| 794 | 586 |
| 795 PRInt32 | 587 PRInt32 |
| 796 _PR_MD_STAT(const char *fn, struct stat *info) | 588 _PR_MD_STAT(const char *fn, struct stat *info) |
| 797 { | 589 { |
| 798 #ifdef WINCE | |
| 799 // needs work. dft | |
| 800 PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0); | |
| 801 return -1; | |
| 802 #else | |
| 803 PRInt32 rv; | 590 PRInt32 rv; |
| 804 | 591 |
| 805 rv = _stat(fn, (struct _stat *)info); | 592 rv = _stat(fn, (struct _stat *)info); |
| 806 if (-1 == rv) { | 593 if (-1 == rv) { |
| 807 /* | 594 /* |
| 808 * Check for MSVC runtime library _stat() bug. | 595 * Check for MSVC runtime library _stat() bug. |
| 809 * (It's really a bug in FindFirstFile().) | 596 * (It's really a bug in FindFirstFile().) |
| 810 * If a pathname ends in a backslash or slash, | 597 * If a pathname ends in a backslash or slash, |
| 811 * e.g., c:\temp\ or c:/temp/, _stat() will fail. | 598 * e.g., c:\temp\ or c:/temp/, _stat() will fail. |
| 812 * Note: a pathname ending in a slash (e.g., c:/temp/) | 599 * Note: a pathname ending in a slash (e.g., c:/temp/) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 824 strcpy(newfn, fn); | 611 strcpy(newfn, fn); |
| 825 newfn[len - 1] = '\0'; | 612 newfn[len - 1] = '\0'; |
| 826 rv = _stat(newfn, (struct _stat *)info); | 613 rv = _stat(newfn, (struct _stat *)info); |
| 827 } | 614 } |
| 828 } | 615 } |
| 829 | 616 |
| 830 if (-1 == rv) { | 617 if (-1 == rv) { |
| 831 _PR_MD_MAP_STAT_ERROR(errno); | 618 _PR_MD_MAP_STAT_ERROR(errno); |
| 832 } | 619 } |
| 833 return rv; | 620 return rv; |
| 834 #endif | |
| 835 } | 621 } |
| 836 | 622 |
| 837 #define _PR_IS_SLASH(ch) ((ch) == '/' || (ch) == '\\') | 623 #define _PR_IS_SLASH(ch) ((ch) == '/' || (ch) == '\\') |
| 838 | 624 |
| 839 static PRBool | 625 static PRBool |
| 840 IsPrevCharSlash(const char *str, const char *current) | 626 IsPrevCharSlash(const char *str, const char *current) |
| 841 { | 627 { |
| 842 const char *prev; | 628 const char *prev; |
| 843 | 629 |
| 844 if (str >= current) | 630 if (str >= current) |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 928 } | 714 } |
| 929 rv = GetDriveType(fn) > 1 ? PR_TRUE : PR_FALSE; | 715 rv = GetDriveType(fn) > 1 ? PR_TRUE : PR_FALSE; |
| 930 /* restore the 'fn' buffer */ | 716 /* restore the 'fn' buffer */ |
| 931 if (slashAdded) { | 717 if (slashAdded) { |
| 932 *--p = '\0'; | 718 *--p = '\0'; |
| 933 } | 719 } |
| 934 } | 720 } |
| 935 return rv; | 721 return rv; |
| 936 } | 722 } |
| 937 | 723 |
| 938 #ifndef WINCE | |
| 939 /* | |
| 940 * InitGetFileInfo -- | |
| 941 * | |
| 942 * Called during IO init. Checks for the existence of the system function | |
| 943 * GetFileAttributeEx, which when available is used in GETFILEINFO calls. | |
| 944 * If the routine exists, then the address of the routine is stored in the | |
| 945 * variable getFileAttributesEx, which will be used to call the routine. | |
| 946 */ | |
| 947 static void InitGetFileInfo(void) | |
| 948 { | |
| 949 HMODULE module; | |
| 950 module = GetModuleHandle("Kernel32.dll"); | |
| 951 if (!module) { | |
| 952 PR_LOG(_pr_io_lm, PR_LOG_DEBUG, | |
| 953 ("InitGetFileInfo: GetModuleHandle() failed: %d", | |
| 954 GetLastError())); | |
| 955 return; | |
| 956 } | |
| 957 | |
| 958 getFileAttributesEx = (GetFileAttributesExFn) | |
| 959 GetProcAddress(module, "GetFileAttributesExA"); | |
| 960 } | |
| 961 | |
| 962 /* | |
| 963 * If GetFileAttributeEx doesn't exist, we call FindFirstFile as a | |
| 964 * fallback. | |
| 965 */ | |
| 966 static BOOL | |
| 967 GetFileAttributesExFB(const char *fn, WIN32_FIND_DATA *findFileData) | |
| 968 { | |
| 969 HANDLE hFindFile; | |
| 970 | |
| 971 /* | |
| 972 * FindFirstFile() expands wildcard characters. So | |
| 973 * we make sure the pathname contains no wildcard. | |
| 974 */ | |
| 975 if (NULL != _mbspbrk(fn, "?*")) { | |
| 976 SetLastError(ERROR_INVALID_NAME); | |
| 977 return FALSE; | |
| 978 } | |
| 979 | |
| 980 hFindFile = FindFirstFile(fn, findFileData); | |
| 981 if (INVALID_HANDLE_VALUE == hFindFile) { | |
| 982 DWORD len; | |
| 983 char *filePart; | |
| 984 char pathbuf[MAX_PATH + 1]; | |
| 985 | |
| 986 /* | |
| 987 * FindFirstFile() does not work correctly on root directories. | |
| 988 * It also doesn't work correctly on a pathname that ends in a | |
| 989 * slash. So we first check to see if the pathname specifies a | |
| 990 * root directory. If not, and if the pathname ends in a slash, | |
| 991 * we remove the final slash and try again. | |
| 992 */ | |
| 993 | |
| 994 /* | |
| 995 * If the pathname does not contain ., \, and /, it cannot be | |
| 996 * a root directory or a pathname that ends in a slash. | |
| 997 */ | |
| 998 if (NULL == _mbspbrk(fn, ".\\/")) { | |
| 999 return FALSE; | |
| 1000 } | |
| 1001 len = GetFullPathName(fn, sizeof(pathbuf), pathbuf, | |
| 1002 &filePart); | |
| 1003 if (0 == len) { | |
| 1004 return FALSE; | |
| 1005 } | |
| 1006 if (len > sizeof(pathbuf)) { | |
| 1007 SetLastError(ERROR_FILENAME_EXCED_RANGE); | |
| 1008 return FALSE; | |
| 1009 } | |
| 1010 if (IsRootDirectory(pathbuf, sizeof(pathbuf))) { | |
| 1011 findFileData->dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY; | |
| 1012 /* The file size doesn't have a meaning for directories. */ | |
| 1013 findFileData->nFileSizeHigh = 0; | |
| 1014 findFileData->nFileSizeLow = 0; | |
| 1015 /* | |
| 1016 * For a directory, these timestamps all specify when the | |
| 1017 * directory is created. The creation time doesn't make | |
| 1018 * sense for root directories, so we set it to (NSPR) time 0. | |
| 1019 */ | |
| 1020 memcpy(&findFileData->ftCreationTime, &_pr_filetime_offset, 8); | |
| 1021 findFileData->ftLastAccessTime = findFileData->ftCreationTime; | |
| 1022 findFileData->ftLastWriteTime = findFileData->ftCreationTime; | |
| 1023 return TRUE; | |
| 1024 } | |
| 1025 if (!IsPrevCharSlash(pathbuf, pathbuf + len)) { | |
| 1026 return FALSE; | |
| 1027 } else { | |
| 1028 pathbuf[len - 1] = '\0'; | |
| 1029 hFindFile = FindFirstFile(pathbuf, findFileData); | |
| 1030 if (INVALID_HANDLE_VALUE == hFindFile) { | |
| 1031 return FALSE; | |
| 1032 } | |
| 1033 } | |
| 1034 } | |
| 1035 | |
| 1036 FindClose(hFindFile); | |
| 1037 return TRUE; | |
| 1038 } | |
| 1039 #endif | |
| 1040 | |
| 1041 PRInt32 | 724 PRInt32 |
| 1042 _PR_MD_GETFILEINFO64(const char *fn, PRFileInfo64 *info) | 725 _PR_MD_GETFILEINFO64(const char *fn, PRFileInfo64 *info) |
| 1043 { | 726 { |
| 1044 #ifdef WINCE | |
| 1045 WIN32_FILE_ATTRIBUTE_DATA findFileData; | 727 WIN32_FILE_ATTRIBUTE_DATA findFileData; |
| 1046 #else | |
| 1047 WIN32_FIND_DATA findFileData; | |
| 1048 #endif | |
| 1049 BOOL rv; | 728 BOOL rv; |
| 1050 | 729 |
| 1051 if (NULL == fn || '\0' == *fn) { | 730 if (NULL == fn || '\0' == *fn) { |
| 1052 PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0); | 731 PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0); |
| 1053 return -1; | 732 return -1; |
| 1054 } | 733 } |
| 1055 | 734 |
| 1056 #ifdef WINCE | 735 rv = GetFileAttributesEx(fn, GetFileExInfoStandard, &findFileData); |
| 1057 rv = GetFileAttributesExA(fn, GetFileExInfoStandard, &findFileData); | |
| 1058 #else | |
| 1059 /* GetFileAttributesEx is supported on Win 2K and up. */ | |
| 1060 if (getFileAttributesEx) { | |
| 1061 rv = getFileAttributesEx(fn, GetFileExInfoStandard, &findFileData); | |
| 1062 } else { | |
| 1063 rv = GetFileAttributesExFB(fn, &findFileData); | |
| 1064 } | |
| 1065 #endif | |
| 1066 if (!rv) { | 736 if (!rv) { |
| 1067 _PR_MD_MAP_OPENDIR_ERROR(GetLastError()); | 737 _PR_MD_MAP_OPENDIR_ERROR(GetLastError()); |
| 1068 return -1; | 738 return -1; |
| 1069 } | 739 } |
| 1070 | 740 |
| 1071 if (findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { | 741 if (findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { |
| 1072 info->type = PR_FILE_DIRECTORY; | 742 info->type = PR_FILE_DIRECTORY; |
| 1073 } else { | 743 } else { |
| 1074 info->type = PR_FILE_FILE; | 744 info->type = PR_FILE_FILE; |
| 1075 } | 745 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1143 info->modifyTime = info64.modifyTime; | 813 info->modifyTime = info64.modifyTime; |
| 1144 info->creationTime = info64.creationTime; | 814 info->creationTime = info64.creationTime; |
| 1145 LL_L2I(info->size, info64.size); | 815 LL_L2I(info->size, info64.size); |
| 1146 } | 816 } |
| 1147 return rv; | 817 return rv; |
| 1148 } | 818 } |
| 1149 | 819 |
| 1150 PRStatus | 820 PRStatus |
| 1151 _PR_MD_SET_FD_INHERITABLE(PRFileDesc *fd, PRBool inheritable) | 821 _PR_MD_SET_FD_INHERITABLE(PRFileDesc *fd, PRBool inheritable) |
| 1152 { | 822 { |
| 1153 #ifdef WINCE | |
| 1154 PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0); | |
| 1155 return PR_FAILURE; | |
| 1156 #else | |
| 1157 BOOL rv; | 823 BOOL rv; |
| 1158 | 824 |
| 1159 /* | 825 /* |
| 1160 * The SetHandleInformation function fails with the | 826 * The SetHandleInformation function fails with the |
| 1161 * ERROR_CALL_NOT_IMPLEMENTED error on Win95. | 827 * ERROR_CALL_NOT_IMPLEMENTED error on Win95. |
| 1162 */ | 828 */ |
| 1163 rv = SetHandleInformation( | 829 rv = SetHandleInformation( |
| 1164 (HANDLE)fd->secret->md.osfd, | 830 (HANDLE)fd->secret->md.osfd, |
| 1165 HANDLE_FLAG_INHERIT, | 831 HANDLE_FLAG_INHERIT, |
| 1166 inheritable ? HANDLE_FLAG_INHERIT : 0); | 832 inheritable ? HANDLE_FLAG_INHERIT : 0); |
| 1167 if (0 == rv) { | 833 if (0 == rv) { |
| 1168 _PR_MD_MAP_DEFAULT_ERROR(GetLastError()); | 834 _PR_MD_MAP_DEFAULT_ERROR(GetLastError()); |
| 1169 return PR_FAILURE; | 835 return PR_FAILURE; |
| 1170 } | 836 } |
| 1171 return PR_SUCCESS; | 837 return PR_SUCCESS; |
| 1172 #endif | |
| 1173 } | 838 } |
| 1174 | 839 |
| 1175 void | 840 void |
| 1176 _PR_MD_INIT_FD_INHERITABLE(PRFileDesc *fd, PRBool imported) | 841 _PR_MD_INIT_FD_INHERITABLE(PRFileDesc *fd, PRBool imported) |
| 1177 { | 842 { |
| 1178 if (imported) { | 843 if (imported) { |
| 1179 fd->secret->inheritable = _PR_TRI_UNKNOWN; | 844 fd->secret->inheritable = _PR_TRI_UNKNOWN; |
| 1180 } else { | 845 } else { |
| 1181 fd->secret->inheritable = _PR_TRI_FALSE; | 846 fd->secret->inheritable = _PR_TRI_FALSE; |
| 1182 } | 847 } |
| 1183 } | 848 } |
| 1184 | 849 |
| 1185 void | 850 void |
| 1186 _PR_MD_QUERY_FD_INHERITABLE(PRFileDesc *fd) | 851 _PR_MD_QUERY_FD_INHERITABLE(PRFileDesc *fd) |
| 1187 { | 852 { |
| 1188 #ifdef WINCE | |
| 1189 fd->secret->inheritable = _PR_TRI_FALSE; | |
| 1190 #else | |
| 1191 DWORD flags; | 853 DWORD flags; |
| 1192 | 854 |
| 1193 PR_ASSERT(_PR_TRI_UNKNOWN == fd->secret->inheritable); | 855 PR_ASSERT(_PR_TRI_UNKNOWN == fd->secret->inheritable); |
| 1194 if (GetHandleInformation((HANDLE)fd->secret->md.osfd, &flags)) { | 856 if (GetHandleInformation((HANDLE)fd->secret->md.osfd, &flags)) { |
| 1195 if (flags & HANDLE_FLAG_INHERIT) { | 857 if (flags & HANDLE_FLAG_INHERIT) { |
| 1196 fd->secret->inheritable = _PR_TRI_TRUE; | 858 fd->secret->inheritable = _PR_TRI_TRUE; |
| 1197 } else { | 859 } else { |
| 1198 fd->secret->inheritable = _PR_TRI_FALSE; | 860 fd->secret->inheritable = _PR_TRI_FALSE; |
| 1199 } | 861 } |
| 1200 } | 862 } |
| 1201 #endif | |
| 1202 } | 863 } |
| 1203 | 864 |
| 1204 PRInt32 | 865 PRInt32 |
| 1205 _PR_MD_RENAME(const char *from, const char *to) | 866 _PR_MD_RENAME(const char *from, const char *to) |
| 1206 { | 867 { |
| 1207 /* Does this work with dot-relative pathnames? */ | 868 /* Does this work with dot-relative pathnames? */ |
| 1208 if (MoveFileA(from, to)) { | 869 if (MoveFileA(from, to)) { |
| 1209 return 0; | 870 return 0; |
| 1210 } else { | 871 } else { |
| 1211 _PR_MD_MAP_RENAME_ERROR(GetLastError()); | 872 _PR_MD_MAP_RENAME_ERROR(GetLastError()); |
| 1212 return -1; | 873 return -1; |
| 1213 } | 874 } |
| 1214 } | 875 } |
| 1215 | 876 |
| 1216 PRInt32 | 877 PRInt32 |
| 1217 _PR_MD_ACCESS(const char *name, PRAccessHow how) | 878 _PR_MD_ACCESS(const char *name, PRAccessHow how) |
| 1218 { | 879 { |
| 1219 #ifdef WINCE | |
| 1220 PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0); | |
| 1221 return -1; | |
| 1222 #else | |
| 1223 PRInt32 rv; | 880 PRInt32 rv; |
| 1224 switch (how) { | 881 switch (how) { |
| 1225 case PR_ACCESS_WRITE_OK: | 882 case PR_ACCESS_WRITE_OK: |
| 1226 rv = _access(name, 02); | 883 rv = _access(name, 02); |
| 1227 break; | 884 break; |
| 1228 case PR_ACCESS_READ_OK: | 885 case PR_ACCESS_READ_OK: |
| 1229 rv = _access(name, 04); | 886 rv = _access(name, 04); |
| 1230 break; | 887 break; |
| 1231 case PR_ACCESS_EXISTS: | 888 case PR_ACCESS_EXISTS: |
| 1232 return _access(name, 00); | 889 return _access(name, 00); |
| 1233 break; | 890 break; |
| 1234 default: | 891 default: |
| 1235 PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0); | 892 PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0); |
| 1236 return -1; | 893 return -1; |
| 1237 } | 894 } |
| 1238 if (rv < 0) | 895 if (rv < 0) |
| 1239 _PR_MD_MAP_ACCESS_ERROR(errno); | 896 _PR_MD_MAP_ACCESS_ERROR(errno); |
| 1240 return rv; | 897 return rv; |
| 1241 #endif | |
| 1242 } | 898 } |
| 1243 | 899 |
| 1244 PRInt32 | 900 PRInt32 |
| 1245 _PR_MD_MKDIR(const char *name, PRIntn mode) | 901 _PR_MD_MKDIR(const char *name, PRIntn mode) |
| 1246 { | 902 { |
| 1247 /* XXXMB - how to translate the "mode"??? */ | 903 /* XXXMB - how to translate the "mode"??? */ |
| 1248 if (CreateDirectoryA(name, NULL)) { | 904 if (CreateDirectoryA(name, NULL)) { |
| 1249 return 0; | 905 return 0; |
| 1250 } else { | 906 } else { |
| 1251 _PR_MD_MAP_MKDIR_ERROR(GetLastError()); | 907 _PR_MD_MAP_MKDIR_ERROR(GetLastError()); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1357 static FindFirstFileWFn findFirstFileW = FindFirstFileW; | 1013 static FindFirstFileWFn findFirstFileW = FindFirstFileW; |
| 1358 typedef BOOL (WINAPI *FindNextFileWFn) (HANDLE, LPWIN32_FIND_DATAW); | 1014 typedef BOOL (WINAPI *FindNextFileWFn) (HANDLE, LPWIN32_FIND_DATAW); |
| 1359 static FindNextFileWFn findNextFileW = FindNextFileW; | 1015 static FindNextFileWFn findNextFileW = FindNextFileW; |
| 1360 typedef DWORD (WINAPI *GetFullPathNameWFn) (LPCWSTR, DWORD, LPWSTR, LPWSTR *); | 1016 typedef DWORD (WINAPI *GetFullPathNameWFn) (LPCWSTR, DWORD, LPWSTR, LPWSTR *); |
| 1361 static GetFullPathNameWFn getFullPathNameW = GetFullPathNameW; | 1017 static GetFullPathNameWFn getFullPathNameW = GetFullPathNameW; |
| 1362 typedef UINT (WINAPI *GetDriveTypeWFn) (LPCWSTR); | 1018 typedef UINT (WINAPI *GetDriveTypeWFn) (LPCWSTR); |
| 1363 static GetDriveTypeWFn getDriveTypeW = GetDriveTypeW; | 1019 static GetDriveTypeWFn getDriveTypeW = GetDriveTypeW; |
| 1364 | 1020 |
| 1365 #endif /* MOZ_UNICODE */ | 1021 #endif /* MOZ_UNICODE */ |
| 1366 | 1022 |
| 1367 PRBool _pr_useUnicode = PR_FALSE; | |
| 1368 | |
| 1369 static void InitUnicodeSupport(void) | |
| 1370 { | |
| 1371 #ifdef WINCE | |
| 1372 /* The A functions don't even exist in Windows Mobile. */ | |
| 1373 _pr_useUnicode = PR_TRUE; | |
| 1374 #else | |
| 1375 /* | |
| 1376 * The W functions exist on Win9x as stubs that fail with the | |
| 1377 * ERROR_CALL_NOT_IMPLEMENTED error. We plan to emulate the | |
| 1378 * MSLU W functions on Win9x in the future. | |
| 1379 */ | |
| 1380 | |
| 1381 /* Find out if we are running on a Unicode enabled version of Windows */ | |
| 1382 OSVERSIONINFOA osvi = {0}; | |
| 1383 | |
| 1384 osvi.dwOSVersionInfoSize = sizeof(osvi); | |
| 1385 if (GetVersionExA(&osvi)) { | |
| 1386 _pr_useUnicode = (osvi.dwPlatformId >= VER_PLATFORM_WIN32_NT); | |
| 1387 } else { | |
| 1388 _pr_useUnicode = PR_FALSE; | |
| 1389 } | |
| 1390 #ifdef DEBUG | |
| 1391 /* | |
| 1392 * In debug builds, allow explicit use of ANSI methods to simulate | |
| 1393 * a Win9x environment for testing purposes. | |
| 1394 */ | |
| 1395 if (getenv("WINAPI_USE_ANSI")) | |
| 1396 _pr_useUnicode = PR_FALSE; | |
| 1397 #endif | |
| 1398 #endif | |
| 1399 } | |
| 1400 | |
| 1401 #ifdef MOZ_UNICODE | 1023 #ifdef MOZ_UNICODE |
| 1402 | 1024 |
| 1403 /* ================ UTF16 Interfaces ================================ */ | 1025 /* ================ UTF16 Interfaces ================================ */ |
| 1404 static void FlipSlashesW(PRUnichar *cp, size_t len) | 1026 static void FlipSlashesW(PRUnichar *cp, size_t len) |
| 1405 { | 1027 { |
| 1406 while (len-- > 0) { | 1028 while (len-- > 0) { |
| 1407 if (cp[0] == L'/') { | 1029 if (cp[0] == L'/') { |
| 1408 cp[0] = L'\\'; | 1030 cp[0] = L'\\'; |
| 1409 } | 1031 } |
| 1410 cp++; | 1032 cp++; |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1744 info->creationTime = info->modifyTime; | 1366 info->creationTime = info->modifyTime; |
| 1745 } else { | 1367 } else { |
| 1746 _PR_FileTimeToPRTime(&findFileData.ftCreationTime, | 1368 _PR_FileTimeToPRTime(&findFileData.ftCreationTime, |
| 1747 &info->creationTime); | 1369 &info->creationTime); |
| 1748 } | 1370 } |
| 1749 | 1371 |
| 1750 return 0; | 1372 return 0; |
| 1751 } | 1373 } |
| 1752 /* ================ end of UTF16 Interfaces ================================ */ | 1374 /* ================ end of UTF16 Interfaces ================================ */ |
| 1753 #endif /* MOZ_UNICODE */ | 1375 #endif /* MOZ_UNICODE */ |
| OLD | NEW |