summaryrefslogtreecommitdiff
path: root/pr/src/md/windows/w95io.c
diff options
context:
space:
mode:
Diffstat (limited to 'pr/src/md/windows/w95io.c')
-rw-r--r--pr/src/md/windows/w95io.c99
1 files changed, 51 insertions, 48 deletions
diff --git a/pr/src/md/windows/w95io.c b/pr/src/md/windows/w95io.c
index 5d483cea..f418fce7 100644
--- a/pr/src/md/windows/w95io.c
+++ b/pr/src/md/windows/w95io.c
@@ -20,6 +20,7 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
+ * Masayuki Nakano <masayuki@d-toybox.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@@ -80,9 +81,9 @@ static const PRTime _pr_filetime_offset = 116444736000000000LL;
static const PRTime _pr_filetime_offset = 116444736000000000i64;
#endif
-#ifdef MOZ_UNICODE
static void InitUnicodeSupport(void);
-#endif
+
+static PRBool IsPrevCharSlash(const char *str, const char *current);
void
_PR_MD_INIT_IO()
@@ -121,9 +122,9 @@ _PR_MD_INIT_IO()
_PR_NT_InitSids();
-#ifdef MOZ_UNICODE
InitUnicodeSupport();
-#endif
+
+ _PR_MD_InitSockets();
}
PRStatus
@@ -516,7 +517,7 @@ _PR_MD_OPEN_DIR(_MDDir *d, const char *name)
* If 'name' ends in a slash or backslash, do not append
* another backslash.
*/
- if (filename[len - 1] == '/' || filename[len - 1] == '\\') {
+ if (IsPrevCharSlash(filename, filename + len)) {
len--;
}
strcpy(&filename[len], "\\*.*");
@@ -654,7 +655,7 @@ _PR_MD_STAT(const char *fn, struct stat *info)
int len = strlen(fn);
if (len > 0 && len <= _MAX_PATH
- && (fn[len - 1] == '\\' || fn[len - 1] == '/')) {
+ && IsPrevCharSlash(fn, fn + len)) {
char newfn[_MAX_PATH + 1];
strcpy(newfn, fn);
@@ -671,6 +672,17 @@ _PR_MD_STAT(const char *fn, struct stat *info)
#define _PR_IS_SLASH(ch) ((ch) == '/' || (ch) == '\\')
+static PRBool
+IsPrevCharSlash(const char *str, const char *current)
+{
+ const char *prev;
+
+ if (str >= current)
+ return PR_FALSE;
+ prev = _mbsdec(str, current);
+ return (prev == current - 1) && _PR_IS_SLASH(*prev);
+}
+
/*
* IsRootDirectory --
*
@@ -717,7 +729,7 @@ IsRootDirectory(char *fn, size_t buflen)
/* look for the next slash */
do {
- p++;
+ p = _mbsinc(p);
} while (*p != '\0' && !_PR_IS_SLASH(*p));
if (*p == '\0') {
return PR_FALSE;
@@ -731,7 +743,7 @@ IsRootDirectory(char *fn, size_t buflen)
/* look for the final slash */
do {
- p++;
+ p = _mbsinc(p);
} while (*p != '\0' && !_PR_IS_SLASH(*p));
if (_PR_IS_SLASH(*p) && p[1] != '\0') {
return PR_FALSE;
@@ -821,7 +833,7 @@ _PR_MD_GETFILEINFO64(const char *fn, PRFileInfo64 *info)
info->creationTime = 0;
return 0;
}
- if (!_PR_IS_SLASH(pathbuf[len - 1])) {
+ if (!IsPrevCharSlash(pathbuf, pathbuf + len)) {
_PR_MD_MAP_OPENDIR_ERROR(GetLastError());
return -1;
} else {
@@ -1106,38 +1118,49 @@ _PR_MD_PIPEAVAILABLE(PRFileDesc *fd)
#ifdef MOZ_UNICODE
typedef HANDLE (WINAPI *CreateFileWFn) (LPCWSTR, DWORD, DWORD, LPSECURITY_ATTRIBUTES, DWORD, DWORD, HANDLE);
-static CreateFileWFn createFileW = NULL;
+static CreateFileWFn createFileW = CreateFileW;
typedef HANDLE (WINAPI *FindFirstFileWFn) (LPCWSTR, LPWIN32_FIND_DATAW);
-static FindFirstFileWFn findFirstFileW = NULL;
+static FindFirstFileWFn findFirstFileW = FindFirstFileW;
typedef BOOL (WINAPI *FindNextFileWFn) (HANDLE, LPWIN32_FIND_DATAW);
-static FindNextFileWFn findNextFileW = NULL;
+static FindNextFileWFn findNextFileW = FindNextFileW;
typedef DWORD (WINAPI *GetFullPathNameWFn) (LPCWSTR, DWORD, LPWSTR, LPWSTR *);
-static GetFullPathNameWFn getFullPathNameW = NULL;
+static GetFullPathNameWFn getFullPathNameW = GetFullPathNameW;
typedef UINT (WINAPI *GetDriveTypeWFn) (LPCWSTR);
-static GetDriveTypeWFn getDriveTypeW = NULL;
+static GetDriveTypeWFn getDriveTypeW = GetDriveTypeW;
+
+#endif /* MOZ_UNICODE */
+
+PRBool _pr_useUnicode = PR_FALSE;
static void InitUnicodeSupport(void)
{
- HMODULE module;
-
/*
- * The W functions do not exist on Win9x. NSPR won't run on Win9x
- * if we call the W functions directly. Use GetProcAddress() to
- * look up their addresses at run time.
+ * The W functions exist on Win9x as stubs that fail with the
+ * ERROR_CALL_NOT_IMPLEMENTED error. We plan to emulate the
+ * MSLU W functions on Win9x in the future.
*/
- module = GetModuleHandle("Kernel32.dll");
- if (!module) {
- return;
- }
+ /* Find out if we are running on a Unicode enabled version of Windows */
+ OSVERSIONINFOA osvi = {0};
- createFileW = (CreateFileWFn)GetProcAddress(module, "CreateFileW");
- findFirstFileW = (FindFirstFileWFn)GetProcAddress(module, "FindFirstFileW");
- findNextFileW = (FindNextFileWFn)GetProcAddress(module, "FindNextFileW");
- getDriveTypeW = (GetDriveTypeWFn)GetProcAddress(module, "GetDriveTypeW");
- getFullPathNameW = (GetFullPathNameWFn)GetProcAddress(module, "GetFullPathNameW");
+ osvi.dwOSVersionInfoSize = sizeof(osvi);
+ if (GetVersionExA(&osvi)) {
+ _pr_useUnicode = (osvi.dwPlatformId >= VER_PLATFORM_WIN32_NT);
+ } else {
+ _pr_useUnicode = PR_FALSE;
+ }
+#ifdef DEBUG
+ /*
+ * In debug builds, allow explicit use of ANSI methods to simulate
+ * a Win9x environment for testing purposes.
+ */
+ if (getenv("WINAPI_USE_ANSI"))
+ _pr_useUnicode = PR_FALSE;
+#endif
}
+#ifdef MOZ_UNICODE
+
/* ================ UTF16 Interfaces ================================ */
void FlipSlashesW(PRUnichar *cp, int len)
{
@@ -1161,11 +1184,6 @@ _PR_MD_OPEN_FILE_UTF16(const PRUnichar *name, PRIntn osflags, int mode)
PSECURITY_DESCRIPTOR pSD = NULL;
PACL pACL = NULL;
- if (!createFileW) {
- PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
- return -1;
- }
-
if (osflags & PR_CREATE_FILE) {
if (_PR_NT_MakeSecurityDescriptorACL(mode, fileAccessTable,
&pSD, &pACL) == PR_SUCCESS) {
@@ -1221,11 +1239,6 @@ _PR_MD_OPEN_DIR_UTF16(_MDDirUTF16 *d, const PRUnichar *name)
PRUnichar filename[ MAX_PATH ];
int len;
- if (!findFirstFileW) {
- PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
- return PR_FAILURE;
- }
-
len = wcslen(name);
/* Need 5 bytes for \*.* and the trailing null byte. */
if (len + 5 > MAX_PATH) {
@@ -1261,11 +1274,6 @@ _PR_MD_READ_DIR_UTF16(_MDDirUTF16 *d, PRIntn flags)
BOOL rv;
PRUnichar *fileName;
- if (!findNextFileW) {
- PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
- return NULL;
- }
-
if ( d ) {
while (1) {
if (d->firstEntry) {
@@ -1411,11 +1419,6 @@ _PR_MD_GETFILEINFO64_UTF16(const PRUnichar *fn, PRFileInfo64 *info)
WIN32_FIND_DATAW findFileData;
PRUnichar pathbuf[MAX_PATH + 1];
- if (!findFirstFileW || !getFullPathNameW || !getDriveTypeW) {
- PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
- return -1;
- }
-
if (NULL == fn || L'\0' == *fn) {
PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
return -1;