From 62f866e3701e5699da4edfa4fb30803d9df63e70 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 18 Jan 2021 12:57:35 -0800 Subject: [PATCH] Bumped prefix checker on is_text_file --- bp.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bp.c b/bp.c index 3abaef1..66299f9 100644 --- a/bp.c +++ b/bp.c @@ -48,6 +48,9 @@ static const char *usage = ( " -c --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 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);