VirtualBox

Changeset 2446 in kBuild for trunk/src


Ignore:
Timestamp:
Jul 7, 2011 11:58:12 AM (14 years ago)
Author:
bird
Message:

2nd try at fopen.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/restartable-syscall-wrappers.c

    r2445 r2446  
    5858#endif
    5959
    60 /** Optional '64' suffix string for dlsym.  */
    61 #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
    62 # define SYM_64_SUFFIX "64"
    63 #else
    64 # define SYM_64_SUFFIX ""
    65 #endif
    66 
    6760/** Mangle a syscall name with optional '64' suffix. */
    6861#if !defined(_LP64) && _FILE_OFFSET_BITS == 64
     
    7972#endif
    8073
     74/** Used by XSTR. */
     75#define XSTR_INNER(x)   #x
     76/** Returns the expanded argument as a string. */
     77#define XSTR(x)         XSTR_INNER(x)
     78
     79
    8180
    8281extern int WRAP64(open)(const char *pszName, int fFlags, ...);
     
    155154    void        *pvLibc;
    156155    void        *pvSym;
     156
     157    /*
     158     * Use the RTLD_NEXT dl feature if present, it's designed for doing
     159     * exactly what we want here.
     160     */
     161#ifdef RTLD_NEXT
     162    pvSym = dlsym(RTLD_NEXT, pszSymbol);
     163    if (pvSym)
     164    {
     165        *ppvSym = pvSym;
     166        return 0;
     167    }
     168#endif
    157169
    158170    /*
     
    163175    {
    164176#ifdef RTLD_NOLOAD
    165         pvLibc = dlopen("/libc/libc.so", RTLD_NOLOAD);
    166 #else
    167         pvLibc = dlopen("/libc/libc.so", RTLD_GLOBAL);
     177        unsigned fFlags = RTLD_NOLOAD | RTLD_NOW;
     178#else
     179        unsigned fFlags = RTLD_GLOBAL | RTLD_NOW;
     180#endif
     181#ifdef KBUILD_OS_LINUX
     182        pvLibc = dlopen("/lib/libc.so.6", fFlags);
     183#else
     184        pvLibc = dlopen("/lib/libc.so", fFlags);
    168185#endif
    169186        if (!pvLibc)
     
    197214    static union
    198215    {
    199         FILE *(* pfnFopen)(const char *, const char *);
     216        FILE *(* pfnFOpen)(const char *, const char *);
    200217        void *pvSym;
    201218    } s_u;
    202219    FILE *pFile;
    203220
    204     if (   !s_u.pfnFopen
    205         && dlsym_libc("fopen" SYM_64_SUFFIX, &s_u.pvSym) != 0)
     221    if (   !s_u.pfnFOpen
     222        && dlsym_libc("fopen", &s_u.pvSym) != 0)
    206223        return NULL;
    207224
    208225    do
    209         pFile = s_u.pfnFopen(pszName, pszMode);
     226        pFile = s_u.pfnFOpen(pszName, pszMode);
    210227    while (!pFile && SHOULD_RESTART());
    211228    return pFile;
    212229}
    213230
     231FILE *fopen64(const char *pszName, const char *pszMode)
     232{
     233    static union
     234    {
     235        FILE *(* pfnFOpen64)(const char *, const char *);
     236        void *pvSym;
     237    } s_u;
     238    FILE *pFile;
     239
     240    if (   !s_u.pfnFOpen64
     241        && dlsym_libc("fopen64", &s_u.pvSym) != 0)
     242        return NULL;
     243
     244    do
     245        pFile = s_u.pfnFOpen64(pszName, pszMode);
     246    while (!pFile && SHOULD_RESTART());
     247    return pFile;
     248}
     249
    214250/** @todo chmod, chown, chgrp, times, and possible some more. */
    215251
    216 
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette