Updated source code for open_fix (FWIW...)

This is a discussion on Updated source code for open_fix (FWIW...) within the awk forums in Programming Languages category; /* A lib to fix the GAWK missing files problem */ /* Usage: export LD_PRELOAD=/path/to/this/lib */ #define _GNU_SOURCE #include <dlfcn.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <time.h> int open64(const char *path, int flags, ...) { static int (*real_open64) (const char *,int); static char *warn; int ret; if (!real_open64) { real_open64 = (int (*)(const char *,int)) dlsym(RTLD_NEXT,"open64"); if ((warn = getenv("OPENFIX_WARN"))) { long t = time(0); fprintf(stderr,"openfix: Initializing at: %s",ctime(&t)); } } if ((ret = real_open64(path,flags)) != -1) return ret; if (warn) fprintf(stderr,"openfix: open failed for '%s' (flags = %d)\n",path,flags); return real_open64("/dev/null",flags); }...

Go Back   Application Development Forum > Programming Languages > awk

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-20-2008, 05:54 PM
Kenny McCormack
Guest
 
Default Updated source code for open_fix (FWIW...)

/* A lib to fix the GAWK missing files problem */
/* Usage: export LD_PRELOAD=/path/to/this/lib */
#define _GNU_SOURCE
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <time.h>


int open64(const char *path, int flags, ...) {
static int (*real_open64) (const char *,int);
static char *warn;
int ret;

if (!real_open64) {
real_open64 = (int (*)(const char *,int)) dlsym(RTLD_NEXT,"open64");
if ((warn = getenv("OPENFIX_WARN"))) {
long t = time(0);
fprintf(stderr,"openfix: Initializing at: %s",ctime(&t));
}
}
if ((ret = real_open64(path,flags)) != -1) return ret;
if (warn)
fprintf(stderr,"openfix: open failed for '%s' (flags = %d)\n",path,flags);
return real_open64("/dev/null",flags);
}
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 07:31 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.