summaryrefslogtreecommitdiff
path: root/quickexec/johns/so_stub.c
blob: fe71f9c1f46ecd3f55657622ebf0d122e8b59383 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <stdio.h>
#include <string.h>
#include <dlfcn.h>


int main( int argc, char *argv[] ) {
    char module[1024];
    int (*loadedMain)( int argc, char *argv[] );
    char *error;
    int retVal = 0;
    void *handle;
    strcpy( module, argv[0] );
    strcat( module, ".so" );
    if ( !(handle  = dlopen( module, RTLD_LAZY ) ) )
	fputs( dlerror(), stderr ), exit( 1 );
    loadedMain = dlsym( handle, "main" );
    if ( ( error = dlerror() ) != NULL )
	fputs( error, stderr ), exit( 1 );
    retVal = (*loadedMain)( argc, argv );
    dlclose( handle );
    return retVal;
}