<commit_before>#define _GNU_SOURCE
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <dlfcn.h>
#include <string.h>
#include <pthread.h>

int (*_original_open)(const char *pathname, int flags, mode_t mode);
int (*_original_close)(int fd);

void init(void) __attribute__((constructor));
int open(const char *pathname, int flags, mode_t mode);
int close(int fd);

static void store_pageinfo(int fd);
static void free_unclaimed_pages(int fd);
extern int fadv_dontneed(int fd, off_t offset, off_t len);
extern int fadv_noreuse(int fd, off_t offset, off_t len);
extern void sync_if_writable(int fd);

#define _MAX_FDS 1024

struct fadv_info {
    int fd;
    off_t size;
    unsigned int nr_pages;
    unsigned char *info;
};
static struct fadv_info fds[_MAX_FDS];
static size_t PAGESIZE;
static pthread_mutex_t lock; /* protects access to fds[] */

void init(void)
{
    int i;
    _original_open = (int (*)(const char *, int, mode_t))
        dlsym(RTLD_NEXT, "open");
    _original_close = (int (*)(int)) dlsym(RTLD_NEXT, "close");
    pthread_mutex_init(&lock, NULL);
    PAGESIZE = getpagesize();
    for(i = 0; i < _MAX_FDS; i++)
        fds[i].fd = -1;
}

int open(const char *pathname, int flags, mode_t mode)
{
    int fd;
    if((fd = _original_open(pathname, flags, mode)) != -1) {
        store_pageinfo(fd);
        fadv_noreuse(fd, 0, 0);
    }
    return fd;
}

int close(int fd)
{
    free_unclaimed_pages(fd);
    return _original_close(fd);
}<commit_msg>intercept openat(), too<commit_after>#define _GNU_SOURCE
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <dlfcn.h>
#include <string.h>
#include <pthread.h>

int (*_original_open)(const char *pathname, int flags, mode_t mode);
int (*_original_openat)(int dirfd, const char *pathname, int flags, mode_t mode);
int (*_original_close)(int fd);

void init(void) __attribute__((constructor));
int open(const char *pathname, int flags, mode_t mode);
int close(int fd);

static void store_pageinfo(int fd);
static void free_unclaimed_pages(int fd);
extern int fadv_dontneed(int fd, off_t offset, off_t len);
extern int fadv_noreuse(int fd, off_t offset, off_t len);
extern void sync_if_writable(int fd);

#define _MAX_FDS 1024

struct fadv_info {
    int fd;
    off_t size;
    unsigned int nr_pages;
    unsigned char *info;
};
static struct fadv_info fds[_MAX_FDS];
static size_t PAGESIZE;
static pthread_mutex_t lock; /* protects access to fds[] */

void init(void)
{
    int i;
    _original_open = (int (*)(const char *, int, mode_t))
        dlsym(RTLD_NEXT, "open");
    _original_openat = (int (*)(int, const char *, int, mode_t))
        dlsym(RTLD_NEXT, "openat");
    _original_close = (int (*)(int)) dlsym(RTLD_NEXT, "close");
    pthread_mutex_init(&lock, NULL);
    PAGESIZE = getpagesize();
    for(i = 0; i < _MAX_FDS; i++)
        fds[i].fd = -1;
}

int open(const char *pathname, int flags, mode_t mode)
{
    int fd;
    if((fd = _original_open(pathname, flags, mode)) != -1) {
        store_pageinfo(fd);
        fadv_noreuse(fd, 0, 0);
    }
    return fd;
}

int openat(int dirfd, const char *pathname, int flags, mode_t mode)
{
    int fd;
    if((fd = _original_openat(dirfd, pathname, flags, mode)) != -1) {
        store_pageinfo(fd);
        fadv_noreuse(fd, 0, 0);
    }
    return fd;
}

int close(int fd)
{
    free_unclaimed_pages(fd);
    return _original_close(fd);
}
{'fraction_non_alphanumeric': 0.13877088643443783, 'fraction_numerical': 0.00594732370433305, 'mean_word_length': 4.074712643678161, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7091561', 'n_tokens_mistral': 1375, 'n_tokens_neox': 1330, 'n_words': 359}