Esempio n. 1
0
/* Make
 */
static
rc_t KSymAddrMake ( KSymAddr **symp,
    const KDylib *lib, const char *name )
{
    void *addr = dlsym ( lib -> handle, name );
    const char *estr = dlerror();

    if ( addr == NULL  &&  builtins != NULL )
    {
        String   builtin_name;
        KSymbol *builtin_sym;
        StringInitCString ( & builtin_name, name );
        builtin_sym = KSymTableFind ( builtins, & builtin_name );
        if ( builtin_sym != NULL ) {
            addr = builtin_sym -> u . obj;
        }
    }
    
    if ( addr != NULL || estr == NULL )
    {
        KSymAddr *sym = malloc ( sizeof * sym );
        if ( sym == NULL )
            return RC ( rcFS, rcDylib, rcConstructing, rcMemory, rcExhausted );

        sym -> lib = KDylibAttach ( lib );
        sym -> addr = addr;
        KRefcountInit ( & sym -> refcount, 1, "KSymAddr", "make", name );
        * symp = sym;
        return 0;
    }

    * symp = NULL;
    return RC ( rcFS, rcDylib, rcSelecting, rcName, rcNotFound );
}
Esempio n. 2
0
static
bool VTableNameAvail ( const KSymTable *tbl, const char *name )
{
    String str;

    /* build a physical name from simple name */
    char pname [ 256 ];
    int len = snprintf ( pname, sizeof pname, ".%s", name );
    if ( len < 0 || len >= sizeof pname )
        return false;

    /* test for defined physical name */
    StringInit ( & str, pname, len, len );
    if ( KSymTableFind ( tbl, & str ) != NULL )
        return false;

    /* test for defined simple name */
    StringSubstr ( & str, & str, 1, 0 );
    if ( KSymTableFind ( tbl, & str ) != NULL )
        return false;

    /* name is available */
    return true;
}