Annotation of sbbs/src/xpdev/xp_dl.c, revision 1.1.1.1

1.1       root        1: #include <stdio.h>
                      2: #include "dirwrap.h"
                      3: #include "xp_dl.h"
                      4: 
                      5: #ifndef STATIC_LINK
                      6: #if defined(__unix__)
                      7: 
                      8: DLLEXPORT dll_handle DLLCALL xp_dlopen(const char **names, int mode, int major)
                      9: {
                     10:        const char      *name;
                     11:        char            fname[MAX_PATH+1];
                     12:        dll_handle      ret=NULL;
                     13:        int                     i;
                     14: 
                     15:        for(; *names && (*names)[0]; names++) {
                     16:                name=*names;
                     17:                /* Try for version match */
                     18:                sprintf(fname, "lib%s.so.%d", name, major);
                     19:                if((ret=dlopen(fname, mode))!=NULL)
                     20:                        return(ret);
                     21: 
                     22:                /* Try for name match */
                     23:                sprintf(fname, "lib%s.so", name, major);
                     24:                if((ret=dlopen(fname, mode))!=NULL)
                     25:                        return(ret);
                     26: 
                     27:                /* Try for name match without the prefix */
                     28:                sprintf(fname, "%s.so", name, major);
                     29:                if((ret=dlopen(fname, mode))!=NULL)
                     30:                        return(ret);
                     31: 
                     32:                /* Try all previous major versions */
                     33:                for(i=major-1; i>=0; i--) {
                     34:                        sprintf(fname, "lib%s.so.%d", name, i);
                     35:                        if((ret=dlopen(fname, mode))!=NULL)
                     36:                                return(ret);
                     37:                }
                     38: 
                     39: #if defined(__APPLE__) && defined(__MACH__)
                     40:                /* Try for version match */
                     41:                sprintf(fname, "lib%s.%d.dylib", name, major);
                     42:                if((ret=dlopen(fname, mode))!=NULL)
                     43:                        return(ret);
                     44: 
                     45:                /* Try for name match */
                     46:                sprintf(fname, "lib%s.dylib", name, major);
                     47:                if((ret=dlopen(fname, mode))!=NULL)
                     48:                        return(ret);
                     49: 
                     50:                /* Try all previous major versions */
                     51:                for(i=major-1; i>=0; i--) {
                     52:                        sprintf(fname, "lib%s.%d.dylib", name, i);
                     53:                        if((ret=dlopen(fname, mode))!=NULL)
                     54:                                return(ret);
                     55:                }
                     56: #endif /* OS X */
                     57:        }
                     58: 
                     59:        return(NULL);
                     60: }
                     61: #elif defined(_WIN32)
                     62: DLLEXPORT dll_handle DLLCALL xp_dlopen(const char **names, int mode, int major)
                     63: {
                     64:        char            fname[MAX_PATH+1];
                     65:        dll_handle      ret=NULL;
                     66: 
                     67:        for(; *names && (*names)[0]; names++) {
                     68:                sprintf(fname, "%s.dll", *names);
                     69:                if((ret=LoadLibrary(fname))!=NULL)
                     70:                        return(ret);
                     71:        }
                     72:        return(NULL);
                     73: }
                     74: #endif /* __unix__,_WIN32 */
                     75: 
                     76: #endif /* STATIC_LINK */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.