char *endOfSystemName = strrchr(info.name, '/'); char *endOfPassedName = strrchr(name, '/');
const char *endOfSystemName = strrchr(info.name, '/'); const char *endOfPassedName = strrchr(name, '/');
pr_LoadLibraryByPathname(const char *name, PRIntn flags){    PRLibrary *lm;    PRLibrary* result;    PRInt32 oserr;    if (!_pr_initialized) _PR_ImplicitInitialization();    /* See if library is already loaded */    PR_EnterMonitor(pr_linker_lock);    result = pr_UnlockedFindLibrary(name);    if (result != NULL) goto unlock;    lm = PR_NEWZAP(PRLibrary);    if (lm == NULL) {        oserr = _MD_ERRNO();        goto unlock;    }    lm->staticTable = NULL;#ifdef XP_OS2  /* Why isn't all this stuff in MD code?! */    {        HMODULE h;        UCHAR pszError[_MAX_PATH];        ULONG ulRc = NO_ERROR;          ulRc = DosLoadModule(pszError, _MAX_PATH, (PSZ) name, &h);          if (ulRc != NO_ERROR) {              oserr = ulRc;              PR_DELETE(lm);              goto unlock;          }          lm->name = strdup(name);          lm->dlh  = h;          lm->next = pr_loadmap;          pr_loadmap = lm;    }#endif /* XP_OS2 */#if defined(WIN32) || defined(WIN16)    {    HINSTANCE h;    NODL_PROC *pfn;    h = LoadLibrary(name);    if (h < (HINSTANCE)HINSTANCE_ERROR) {        oserr = _MD_ERRNO();        PR_DELETE(lm);        goto unlock;    }    lm->name = strdup(name);    lm->dlh = h;    lm->next = pr_loadmap;    pr_loadmap = lm;    /*    ** Try to load a table of "static functions" provided by the DLL    */    pfn = (NODL_PROC *)GetProcAddress(h, "NODL_TABLE");    if (pfn != NULL) {        lm->staticTable = (*pfn)();    }    }#endif /* WIN32 || WIN16 */#if defined(XP_MAC) || defined(XP_MACOSX)    {    int     i;    PRStatus status;    static const macLibraryLoadProc loadProcs[] = {#if defined(XP_MACOSX)        pr_LoadViaDyld, pr_LoadCFBundle, pr_LoadViaCFM#elif TARGET_CARBON        pr_LoadViaCFM, pr_LoadCFBundle#else        pr_LoadViaCFM#endif    };    for (i = 0; i < sizeof(loadProcs) / sizeof(loadProcs[0]); i++) {        if ((status = loadProcs[i](name, lm)) == PR_SUCCESS)            break;    }    if (status != PR_SUCCESS) {        oserr = cfragNoLibraryErr;        PR_DELETE(lm);        goto unlock;            }    lm->name = strdup(name);    lm->next = pr_loadmap;    pr_loadmap = lm;    }#endif#if defined(XP_UNIX) && !defined(XP_MACOSX)#ifdef HAVE_DLL    {#if defined(USE_DLFCN)#ifdef NTO    /* Neutrino needs RTLD_GROUP to load Netscape plugins. (bug 71179) */    int dl_flags = RTLD_GROUP;#else    int dl_flags = 0;#endif    void *h;    if (flags & PR_LD_LAZY) {        dl_flags |= RTLD_LAZY;    }    if (flags & PR_LD_NOW) {        dl_flags |= RTLD_NOW;    }    if (flags & PR_LD_GLOBAL) {        dl_flags |= RTLD_GLOBAL;    }    if (flags & PR_LD_LOCAL) {        dl_flags |= RTLD_LOCAL;    }    h = dlopen(name, dl_flags);#elif defined(USE_HPSHL)    int shl_flags = 0;    shl_t h;    /*     * Use the DYNAMIC_PATH flag only if 'name' is a plain file     * name (containing no directory) to match the behavior of     * dlopen().     */    if (strchr(name, PR_DIRECTORY_SEPARATOR) == NULL) {        shl_flags |= DYNAMIC_PATH;    }    if (flags & PR_LD_LAZY) {        shl_flags |= BIND_DEFERRED;    }    if (flags & PR_LD_NOW) {        shl_flags |= BIND_IMMEDIATE;    }    /* No equivalent of PR_LD_GLOBAL and PR_LD_LOCAL. */    h = shl_load(name, shl_flags, 0L);#elif defined(USE_MACH_DYLD)    NSModule h = pr_LoadMachDyldModule(name);#else#error Configuration error#endif    if (!h) {        oserr = _MD_ERRNO();        PR_DELETE(lm);        goto unlock;    }    lm->name = strdup(name);    lm->dlh = h;    lm->next = pr_loadmap;    pr_loadmap = lm;    }#endif /* HAVE_DLL */#endif /* XP_UNIX */    lm->refCount = 1;#ifdef XP_BEOS    {        image_info info;        int32 cookie = 0;        image_id imageid = B_ERROR;        image_id stubid = B_ERROR;        PRLibrary *p;        for (p = pr_loadmap; p != NULL; p = p->next) {            /* hopefully, our caller will always use the same string               to refer to the same library */            if (strcmp(name, p->name) == 0) {                /* we've already loaded this library */                imageid = info.id;                lm->refCount++;                break;            }        }        if(imageid == B_ERROR) {            /* it appears the library isn't yet loaded - load it now */            char stubName [B_PATH_NAME_LENGTH + 1];            /* the following is a work-around to a "bug" in the beos -               the beos system loader allows only 32M (system-wide)               to be used by code loaded as "add-ons" (code loaded               through the 'load_add_on()' system call, which includes               mozilla components), but allows 256M to be used by               shared libraries.                              unfortunately, mozilla is too large to fit into the               "add-on" space, so we must trick the loader into               loading some of the components as shared libraries.  this               is accomplished by creating a "stub" add-on (an empty               shared object), and linking it with the component               (the actual .so file generated by the build process,               without any modifications).  when this stub is loaded               by load_add_on(), the loader will automatically load the               component into the shared library space.            */            strcpy(stubName, name);            strcat(stubName, ".stub");            /* first, attempt to load the stub (thereby loading the               component as a shared library */            if ((stubid = load_add_on(stubName)) > B_ERROR) {                /* the stub was loaded successfully. */                imageid = B_FILE_NOT_FOUND;                cookie = 0;                while (get_next_image_info(0, &cookie, &info) == B_OK) {                    char *endOfSystemName = strrchr(info.name, '/');                    char *endOfPassedName = strrchr(name, '/');                    if( 0 == endOfSystemName )                         endOfSystemName=info.name;                    else                        endOfSystemName++;                    if( 0 == endOfPassedName )                        endOfPassedName=name;                    else                        endOfPassedName++;                    if (strcmp(endOfSystemName, endOfPassedName) == 0) {                        /* this is the actual component - remember it */                        imageid = info.id;                        break;                    }                }            } else {                /* we failed to load the "stub" - try to load the                   component directly as an add-on */                stubid = B_ERROR;                imageid = load_add_on(name);            }        }        if (imageid <= B_ERROR) {            oserr = imageid;            PR_DELETE( lm );            goto unlock;        }        lm->name = strdup(name);        lm->dlh = (void*)imageid;        lm->stub_dlh = (void*)stubid;        lm->next = pr_loadmap;        pr_loadmap = lm;    }#endif    result = lm;    /* success */    PR_LOG(_pr_linker_lm, PR_LOG_MIN, ("Loaded library %s (load lib)", lm->name));  unlock:    if (result == NULL) {        PR_SetError(PR_LOAD_LIBRARY_ERROR, oserr);        DLLErrorInternal(oserr);  /* sets error text */    }    PR_ExitMonitor(pr_linker_lock);    return result;}