// Override "openat"
int openat(int dirfd, const char *pathname, int flags) {
- static int (*real_openat)(int, const char*, int);
- if ( real_openat == 0 ) {
- real_openat = dlsym( libc6, "openat" );
+ static int (*real_openat)(int, const char*, int) = 0;
+ if ( libc6 == 0 ) {
+ void *lib = dlopen( "libc.so.6", RTLD_LAZY );
+ real_openat = dlsym( lib, "openat" );
+ return real_openat( dirfd, pathname, flags );
}
//fprintf( stderr, "openat( %s )\n", pathname );
if ( data.tarmap ) {
// Override "open"
int open(const char *pathname, int flags) {
- static int (*real_open)(const char *pathname, int flags);
- if ( real_open == 0 ) {
- real_open = dlsym( libc6, "open" );
+ static int (*real_open)(const char *pathname, int flags) = 0;
+ if ( libc6 == 0 ) {
+ void *lib = dlopen( "libc.so.6", RTLD_LAZY );
+ real_open = dlsym( lib, "open" );
+ return real_open( pathname, flags );
}
//fprintf( stderr, "open( %s )\n", pathname );
if ( data.tarmap ) {
// Override "fopen"
FILE *fopen(const char *pathname, const char *mode) {
- static FILE *(*real_fopen)(const char *pathname, const char *mode);
+ static FILE *(*real_fopen)(const char *pathname, const char *mode) = 0;
if ( real_fopen == 0 ) {
- real_fopen = dlsym( libc6, "fopen" );
+ void *lib = dlopen( "libc.so.6", RTLD_LAZY );
+ real_fopen = dlsym( lib, "fopen" );
+ return real_fopen( pathname, mode );
}
if ( data.tarmap ) {
FILE *file = tryopentar( pathname );
if ( libc6 ) {
return;
}
- libc6 = dlopen( "libc.so.6", RTLD_LAZY );
char *tarfile = getenv( TARMAP );
if ( tarfile == 0 || *tarfile == 0 ) {
//fprintf( stderr, "(libtarmap: no tar)\n" );
data.tarmap = 0;
return; // Stop here for unset or cleared environment
}
- //fprintf( stderr, "libtarmap: tarfile = %s\n", tarfile );
+ //fprintf( stderr, "libtarmap: %s\n", tarfile? tarfile : "(null)" );
+ libc6 = dlopen( "libc.so.6", RTLD_LAZY );
+ real_openat = dlsym( libc6, "openat" );
+ real_open = dlsym( libc6, "open" );
+ real_fopen = dlsym( libc6, "fopen" );
if ( ( data.tarmap = realpath( tarfile, 0 ) ) == 0 ) {
// Cannot find the tar file .. that's total badness!
perror( tarfile );
perror( data.tarmap );
exit( 1 );
}
+ int fd = fileno( file );
data.buffer = malloc( DATASZ );
- data.size = read( fileno( file ), data.buffer, DATASZ );
+ char *p = data.buffer;
+ int max = DATASZ;
+ int n;
+ while ( ( n = read( fd, p, max ) ) > 0 ) {
+ data.size += n;
+ p += n;
+ max -= n;
+ }
+ //fprintf( stderr, "data.size = %d\n", data.size );
if ( data.size == 0 ) {
perror( cmd );
// Not a tar or empty tar .. that's total badness!
free( cmd );
cmd = 0;
char *end = data.buffer + data.size;
- char *p;
- int n = 0;
+ n = 0;
for ( p = data.buffer; p < end; p++ ) {
if ( *p == '\n' ) {
n++;