Bug 476926: Removed LoadLibraryW and CP_UTF8 emulation for Windows 9x.
authorwtc%google.com
Wed, 04 Feb 2009 21:28:22 +0000
changeset 4030 d6ad63f412f56ab6fa4a5d95aeae3821b4552d5a
parent 4029 6624b287ef961e13bc9383774bda4000e9ede228
child 4031 308ccbdcc8a787f6f7715e84629aa96d43acc0e5
push idunknown
push userunknown
push dateunknown
bugs476926
Bug 476926: Removed LoadLibraryW and CP_UTF8 emulation for Windows 9x. TBR=nelson.
pr/src/linking/prlink.c
--- a/pr/src/linking/prlink.c
+++ b/pr/src/linking/prlink.c
@@ -205,26 +205,16 @@ struct PRLibrary {
 
 static PRLibrary *pr_loadmap;
 static PRLibrary *pr_exe_loadmap;
 static PRMonitor *pr_linker_lock;
 static char* _pr_currentLibPath = NULL;
 
 static PRLibrary *pr_LoadLibraryByPathname(const char *name, PRIntn flags);
 
-#ifdef WIN95
-typedef HMODULE (WINAPI *LoadLibraryWFn)(LPCWSTR);
-static HMODULE WINAPI EmulateLoadLibraryW(LPCWSTR);
-static LoadLibraryWFn loadLibraryW = LoadLibraryW;
-#endif
-
-#ifdef WIN32
-static int pr_ConvertUTF16toUTF8(LPCWSTR wname, LPSTR name, int len);
-#endif
-
 /************************************************************************/
 
 #if !defined(USE_DLFCN) && !defined(HAVE_STRERROR)
 #define ERR_STR_BUF_LENGTH    20
 #endif
 
 static void DLLErrorInternal(PRIntn oserr)
 /*
@@ -249,22 +239,16 @@ static void DLLErrorInternal(PRIntn oser
 
 void _PR_InitLinker(void)
 {
     PRLibrary *lm = NULL;
 #if defined(XP_UNIX)
     void *h;
 #endif
 
-#ifdef WIN95
-    if (!_pr_useUnicode) {
-        loadLibraryW = EmulateLoadLibraryW;
-    }
-#endif
-
     if (!pr_linker_lock) {
         pr_linker_lock = PR_NewNamedMonitor("linker-lock");
     }
     PR_EnterMonitor(pr_linker_lock);
 
 #if defined(XP_PC)
     lm = PR_NEWZAP(PRLibrary);
     lm->name = strdup("Executable");
@@ -775,35 +759,16 @@ pr_LoadViaDyld(const char *name, PRLibra
                     linkEditError, errorNum, fileName, errorString));
         }
     }
     return (lm->dlh != NULL || lm->image != NULL) ? PR_SUCCESS : PR_FAILURE;
 }
 
 #endif /* XP_MACOSX && USE_MACH_DYLD */
 
-#ifdef WIN95
-static HMODULE WINAPI
-EmulateLoadLibraryW(LPCWSTR lpLibFileName)
-{
-    HMODULE h;
-    char nameA[MAX_PATH];
-
-    if (!WideCharToMultiByte(CP_ACP, 0, lpLibFileName, -1,
-                             nameA, sizeof nameA, NULL, NULL)) {
-        return NULL;
-    }
-    /* Perhaps it's better to add a check for characters 
-     * not representable in CP_ACP.
-     */
-    h = LoadLibraryA(nameA);
-    return h;
-}
-#endif /* WIN95 */
-
 /*
 ** Dynamically load a library. Only load libraries once, so scan the load
 ** map first.
 */
 static PRLibrary*
 pr_LoadLibraryByPathname(const char *name, PRIntn flags)
 {
     PRLibrary *lm;
@@ -833,21 +798,22 @@ pr_LoadLibraryByPathname(const char *nam
         if (wlen > MAX_PATH)
             wname = wname_malloc = PR_Malloc(wlen * sizeof(PRUnichar));
         if (wname == NULL ||
             !MultiByteToWideChar(CP_ACP, 0,  name, -1, wname, wlen)) {
             oserr = _MD_ERRNO();
             goto unlock;
         }
     }
-    len = pr_ConvertUTF16toUTF8(wname, NULL, 0);
+    len = WideCharToMultiByte(CP_UTF8, 0, wname, -1, NULL, 0, NULL, NULL);
     if (len > MAX_PATH)
         utf8name = utf8name_malloc = PR_Malloc(len);
     if (utf8name == NULL ||
-        !pr_ConvertUTF16toUTF8(wname, utf8name, len)) {
+        !WideCharToMultiByte(CP_UTF8, 0, wname, -1,
+                             utf8name, len, NULL, NULL)) {
         oserr = _MD_ERRNO();
         goto unlock;
     }
     /* the list of loaded library names are always kept in UTF-8 
      * on Win32 platforms */
     result = pr_UnlockedFindLibrary(utf8name);
 #else
     result = pr_UnlockedFindLibrary(name);
@@ -881,27 +847,20 @@ pr_LoadLibraryByPathname(const char *nam
     }
 #endif /* XP_OS2 */
 
 #if defined(WIN32) || defined(WIN16)
     {
     HINSTANCE h;
 
 #ifdef WIN32
-#ifdef WIN95
-    if (flags & PR_LD_PATHW)
-        h = loadLibraryW(wname);
-    else
-        h = LoadLibraryA(name);
-#else
     if (flags & PR_LD_PATHW)
         h = LoadLibraryW(wname);
     else
         h = LoadLibraryA(name);
-#endif /* WIN95 */
 #else 
     h = LoadLibrary(name);
 #endif
     if (h < (HINSTANCE)HINSTANCE_ERROR) {
         oserr = _MD_ERRNO();
         PR_DELETE(lm);
         goto unlock;
     }
@@ -1115,135 +1074,16 @@ pr_LoadLibraryByPathname(const char *nam
         PR_Free(utf8name_malloc);
     if (wname_malloc)
         PR_Free(wname_malloc);
 #endif
     PR_ExitMonitor(pr_linker_lock);
     return result;
 }
 
-#ifdef WIN32
-#ifdef WIN95
-/*
- * CP_UTF8 is not supported by WideCharToMultiByte on Windows 95 so that 
- * we have to emulate it
- */
-static PRStatus 
-pr_ConvertSingleCharToUTF8(PRUint32 usv, PRUint16 offset, int bufLen,
-                           int *utf8Len, char * *buf)
-{
-    char* p = *buf;
-    PR_ASSERT(!bufLen || *buf);
-    if (!bufLen) {
-        *utf8Len += offset;
-        return PR_SUCCESS;
-    }
-
-    if (*utf8Len + offset >= bufLen)
-        return PR_FAILURE;
-
-    *utf8Len += offset;
-    if (offset == 1) {
-        *p++ = (char) usv;
-    } else if (offset == 2) {
-        *p++ = (char)0xc0 | (usv >> 6);
-        *p++ = (char)0x80 | (usv & 0x003f);
-    } else if (offset == 3) {
-        *p++ = (char)0xe0 | (usv >> 12);
-        *p++ = (char)0x80 | ((usv >> 6) & 0x003f);
-        *p++ = (char)0x80 | (usv & 0x003f);
-    } else { /* offset = 4 */
-        *p++ = (char)0xf0 | (usv >> 18);
-        *p++ = (char)0x80 | ((usv >> 12) & 0x003f);
-        *p++ = (char)0x80 | ((usv >> 6) & 0x003f);
-        *p++ = (char)0x80 | (usv & 0x003f);
-    }
-
-    *buf = p;
-    return PR_SUCCESS;
-}
-
-static int pr_ConvertUTF16toUTF8(LPCWSTR wname, LPSTR name, int len)
-{
-    LPCWSTR pw = wname;
-    LPSTR p = name;
-    int utf8Len = 0;
-    PRBool highSurrogate = PR_FALSE;
-
-    utf8Len = WideCharToMultiByte(CP_UTF8, 0, wname, -1, name, len, 
-                                  NULL, NULL);
-    /*
-     * Windows 95 and NT 3.51 don't support CP_UTF8.
-     * WideCharToMultiByte(CP_UTF8, ...) fails with the error code
-     * ERROR_INVALID_PARAMETER on Windows 95 and NT 3.51.
-     */
-    if (utf8Len || GetLastError() != ERROR_INVALID_PARAMETER)
-        return utf8Len;
-
-    if (!wname || len < 0 || (len > 0 && !name)) {
-        SetLastError(ERROR_INVALID_PARAMETER);
-        return 0;
-    }
-
-    while (*pw) {
-        PRStatus status = PR_SUCCESS;
-        if (highSurrogate) {
-            if (*pw >= (PRUnichar) 0xDC00 && *pw < (PRUnichar) 0xE000) {
-                /* found a matching low surrogate */
-                /* convert a surrogate pair to UCS4 */
-                PRUint32 usv = ((*(pw-1) - (PRUnichar)0xD800) << 10) + 
-                               (*pw - (PRUnichar)0xDC00) + (PRUint32)0x10000;
-                if (pr_ConvertSingleCharToUTF8(usv, 4, len, &utf8Len, &p) ==
-                    PR_FAILURE)
-                    return 0;
-                highSurrogate = PR_FALSE;
-                ++pw;
-                continue;
-            } else {
-                /*
-                 * silently ignore a lone high surrogate
-                 * as is done by WideCharToMultiByte by default
-                 */
-                highSurrogate = PR_FALSE;
-            }
-        }
-        if (*pw <= 0x7f) 
-            status = pr_ConvertSingleCharToUTF8(*pw, 1, len, &utf8Len, &p);
-        else if (*pw <= 0x07ff)
-            status = pr_ConvertSingleCharToUTF8(*pw, 2, len, &utf8Len, &p);
-        else if (*pw < (PRUnichar) 0xD800 || *pw >= (PRUnichar) 0xE000)
-            status = pr_ConvertSingleCharToUTF8(*pw, 3, len, &utf8Len, &p);
-        else if (*pw < (PRUnichar) 0xDC00)
-            highSurrogate = PR_TRUE;
-        /* else */
-        /* silently ignore a lone low surrogate as is done by 
-         * WideCharToMultiByte by default */
-
-        if (status == PR_FAILURE) {
-            SetLastError(ERROR_INSUFFICIENT_BUFFER);
-            return 0;
-        }
-        ++pw;
-    }
-
-    /* if we're concerned with a lone high surrogate,
-     * we have to take care of it here, but we just drop it 
-     */
-    if (len > 0)
-        *p = '\0';
-    return utf8Len + 1;
-}
-#else
-static int pr_ConvertUTF16toUTF8(LPCWSTR wname, LPSTR name, int len)
-{
-    return WideCharToMultiByte(CP_UTF8, 0, wname, -1, name, len, NULL, NULL);
-}
-#endif /* WIN95 */
-#endif /* WIN32 */
-
 /*
 ** Unload a shared library which was loaded via PR_LoadLibrary
 */
 PR_IMPLEMENT(PRStatus) 
 PR_UnloadLibrary(PRLibrary *lib)
 {
     int result = 0;
     PRStatus status = PR_SUCCESS;