diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2021-01-18 12:57:35 -0800 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2021-01-18 12:57:35 -0800 |
| commit | 62f866e3701e5699da4edfa4fb30803d9df63e70 (patch) | |
| tree | e6caba4a8ce64096e6df7f42fe67fa02c3740b68 /bp.c | |
| parent | e82fcefac8af1605c2e930980572c232f4a92e6c (diff) | |
Bumped prefix checker on is_text_file
Diffstat (limited to 'bp.c')
| -rw-r--r-- | bp.c | 5 |
1 files changed, 4 insertions, 1 deletions
@@ -48,6 +48,9 @@ static const char *usage = ( " -c --context <context> set number of lines of context to print (all: the whole file, 0: only the match, 1: the line, N: N lines of context)\n" " -g --grammar <grammar file> use the specified file as a grammar\n"); +// Used as a heuristic to check if a file is binary or text: +#define CHECK_FIRST_N_BYTES 128 + // Flag-configurable options: #define USE_DEFAULT_CONTEXT -2 #define ALL_CONTEXT -1 @@ -132,7 +135,7 @@ static int is_text_file(const char *filename) { int fd = open(filename, O_RDONLY); if (fd < 0) return 0; - char buf[64]; + char buf[CHECK_FIRST_N_BYTES]; ssize_t len = read(fd, buf, sizeof(buf)/sizeof(char)); if (len < 0) return 0; (void)close(fd); |
