All pastes #595744 Raw Edit

Someone

public text v1 · immutable
#595744 ·published 2007-06-29 17:09 UTC
rendered paste body
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <dlfcn.h>

FILE * fopen64(const char * path, const char * mode)
{
    FILE* ret;
    static FILE* (*realopen)(const char * path, const char * mode);

    printf("open: %s\n", path);

    if (!realopen) {
        realopen = dlsym((void *)-1, "fopen64");
    }

    ret = realopen(path, mode);
     
    return ret;
}

ssize_t read(int d, void *buf, size_t nbytes)
{
    ssize_t ret;
    static ssize_t(*realread)(int d, void *buf, size_t nbytes);
    char* c;
    printf("read: %d\n", nbytes);

    if (!realread) {
        realread = dlsym((void *)-1, "read");
    }
    ret = realread(d, buf, nbytes);
    c = (char*)buf;
    printf("r: [%c%c%c%c]\n", c[0], c[1], c[2], c[3]);

    return ret;
}

ssize_t write(int d, const void *buf, size_t nbytes)
{
    ssize_t ret;
    static ssize_t(*realwrite)(int d, const void *buf, size_t nbytes);
    char* c;
    printf("write: %d\n", nbytes);

    if (!realwrite) {
        realwrite = dlsym((void *)-1, "write");
    }
    ret = realwrite(d, buf, nbytes);
    c = (char*)buf;
    printf("w: [%c%c%c%c]\n", c[0], c[1], c[2], c[3]);

    return ret;
}