#include #include #include #include typedef ssize_t (*f)(int fd, void *buf, size_t count); ssize_t read(int fd, void *buf, size_t count) { static f og_read = NULL; static int calls = 0; const int MAX_CALLS = getenv("MAX_READ_CALLS") ? atoi(getenv("MAX_READ_CALLS")) : -1; if (!og_read) { og_read = (f)dlsym(RTLD_NEXT, "read"); } calls++; if (MAX_CALLS < 0 || calls <= MAX_CALLS) { return og_read(fd, buf, count); } errno = EBADF; return -1; }