aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2021-05-18 10:10:35 -0700
committerBruce Hill <bruce@bruce-hill.com>2021-05-18 10:10:35 -0700
commit10532ca614ae279125aec368d591f94383c5bcd5 (patch)
tree280929fab2123d3ce91f89a17819d0eb105a1d58
parent48cb65d2b50c9865e60fe7cd6d13b2844d09151c (diff)
Cleanup
-rw-r--r--bp.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/bp.c b/bp.c
index c3a807b..7899ff0 100644
--- a/bp.c
+++ b/bp.c
@@ -4,6 +4,7 @@
// See `man ./bp.1` for more details
//
+#include <ctype.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
@@ -151,14 +152,10 @@ static int is_text_file(const char *filename)
if (fd < 0) return 0;
char buf[CHECK_FIRST_N_BYTES];
ssize_t len = read(fd, buf, sizeof(buf)/sizeof(char));
- if (len < 0) return 0;
(void)close(fd);
-
- for (ssize_t i = 0; i < len; i++) {
- if (!(buf[i] == '\t' || buf[i] == '\n' || buf[i] == '\r'
- || buf[i] >= '\x20'))
- return 0;
- }
+ if (len < 0) return 0;
+ for (ssize_t i = 0; i < len; i++)
+ if (!isprint(buf[i])) return 0;
return 1;
}