X-Git-Url: http://git.harvie.cz/?a=blobdiff_plain;f=c%2Fcano%2Fold%2Fcano.c;fp=c%2Fcano%2Fold%2Fcano.c;h=1f374b34417abd9ebf805504b8032d46a1ef0f5e;hb=d3b2d1a75c5c62e4d7142124162e2deb8273b32b;hp=0000000000000000000000000000000000000000;hpb=b9a41889280efffe1d21fb094e175f0f204ea039;p=mirrors%2FPrograms.git diff --git a/c/cano/old/cano.c b/c/cano/old/cano.c new file mode 100644 index 0000000..1f374b3 --- /dev/null +++ b/c/cano/old/cano.c @@ -0,0 +1,52 @@ +#define _GNU_SOURCE +#include +#include +#include +#include +#include + + +static const char *fd_to_path(int fd) { + static char path[PATH_MAX]; + sprintf(path,"/proc/self/fd/%d",fd); + int l = (int) readlink((char * __restrict__) path, path, PATH_MAX); + path[l]=0; + return path; +} + +int at_close() { + unsetenv("LD_PRELOAD"); + return system(getenv("AT_CLOSE")); + /* + static const char *command; + if(!command) { + command = getenv("AT_CLOSE"); + unsetenv("LD_PRELOAD"); + } + fprintf(stderr,"%s\n",command); + system(command); + return 0; + */ +} + +int close(int fd) { + //fprintf(stderr,"%s(%d,%s);\n",__func__,fd,fd_to_path(fd)); + static int (*close_orig)(int fd); + if (!close_orig) { + close_orig = dlsym(RTLD_NEXT, "close"); + } + int ret = close_orig(fd); + //int ret = syscall(SYS_close,fd); + at_close(); + return ret; +} +int fclose(FILE *fd) { + //fprintf(stderr,"%s(%d,%d,%s);\n",__func__,fileno(fd),fd,fd_to_path(fileno(fd))); + static int (*fclose_orig)(FILE *fd); + if (!fclose_orig) { + fclose_orig = dlsym(RTLD_NEXT, "fclose"); + } + int ret = fclose_orig(fd); + at_close(); + return ret; +}