<commit_before>#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/xattr.h>

#include "flags.h"

static void apply(const char *flags, size_t flags_len, const char *path) {
    if (setxattr(path, "user.pax.flags", flags, flags_len, 0) == -1) {
        if (errno != ENOENT) {
            fprintf(stderr, "could not apply attributes to %s: %m\n", path);
        }
    }
}

static void line_ignored(size_t n, const char *line) {
    fprintf(stderr, "ignored invalid line %zu in /etc/paxd.conf: %s", n, line);
}

void update_attributes(void) {
    FILE *conf = fopen("/etc/paxd.conf", "r");
    if (!conf) {
        perror("could not open /etc/paxd.conf");
        return;
    }

    char *line = NULL;
    size_t line_len = 0;

    for (size_t n = 1;; n++) {
        ssize_t bytes_read = getline(&line, &line_len, conf);
        if (bytes_read == -1) {
            if (ferror(conf)) {
                perror("failed to read line from /etc/paxd.conf");
                break;
            } else {
                break;
            }
        }

        if (line[0] == '\n' || line[0] == '\0' || line[0] == '#') {
            continue; // ignore empty lines and comments
        }

        const char *flags = line + strspn(line, " \t"); // skip initial whitespace

        const char *split = flags + strcspn(flags, " \t"); // find the end of the specified flags<commit_msg>Do not overflow line number on excessively large files.<commit_after>#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/xattr.h>

#include "flags.h"

static void apply(const char *flags, size_t flags_len, const char *path) {
    if (setxattr(path, "user.pax.flags", flags, flags_len, 0) == -1) {
        if (errno != ENOENT) {
            fprintf(stderr, "could not apply attributes to %s: %m\n", path);
        }
    }
}

static void line_ignored(off_t n, const char *line) {
    fprintf(stderr, "ignored invalid line %lld in /etc/paxd.conf: %s", (long long)n, line);
}

void update_attributes(void) {
    FILE *conf = fopen("/etc/paxd.conf", "r");
    if (!conf) {
        perror("could not open /etc/paxd.conf");
        return;
    }

    char *line = NULL;
    size_t line_len = 0;

    for (off_t n = 1;; n++) {
        ssize_t bytes_read = getline(&line, &line_len, conf);
        if (bytes_read == -1) {
            if (ferror(conf)) {
                perror("failed to read line from /etc/paxd.conf");
                break;
            } else {
                break;
            }
        }

        if (line[0] == '\n' || line[0] == '\0' || line[0] == '#') {
            continue; // ignore empty lines and comments
        }

        const char *flags = line + strspn(line, " \t"); // skip initial whitespace

        const char *split = flags + strcspn(flags, " \t"); // find the end of the specified flags
{'fraction_non_alphanumeric': 0.15646492434662998, 'fraction_numerical': 0.006189821182943604, 'mean_word_length': 2.1585233441910967, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '4161191', 'n_tokens_mistral': 1015, 'n_tokens_neox': 989, 'n_words': 282}