summaryrefslogtreecommitdiff
path: root/usr.bin/file/ascmagic.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/file/ascmagic.c')
-rw-r--r--usr.bin/file/ascmagic.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/usr.bin/file/ascmagic.c b/usr.bin/file/ascmagic.c
index 455f3043b9b..9caa50eff7b 100644
--- a/usr.bin/file/ascmagic.c
+++ b/usr.bin/file/ascmagic.c
@@ -1,4 +1,5 @@
-/* $OpenBSD: ascmagic.c,v 1.2 1996/06/26 05:32:54 deraadt Exp $ */
+/* $OpenBSD: ascmagic.c,v 1.3 1997/02/09 23:58:18 millert Exp $ */
+
/*
* ASCII magic -- file types that we know based on keywords
* that can appear anywhere in the file.
@@ -36,7 +37,7 @@
#include "names.h"
#ifndef lint
-static char *moduleid = "$OpenBSD: ascmagic.c,v 1.2 1996/06/26 05:32:54 deraadt Exp $";
+static char *moduleid = "$OpenBSD: ascmagic.c,v 1.3 1997/02/09 23:58:18 millert Exp $";
#endif /* lint */
/* an optimisation over plain strcmp() */
@@ -88,6 +89,13 @@ int nbytes; /* size actually read */
return 1;
}
+
+ /* Make sure we are dealing with ascii text before looking for tokens */
+ for (i = 0; i < nbytes; i++) {
+ if (!isascii(buf[i]))
+ return 0; /* not all ASCII */
+ }
+
/* look for tokens from names.h - this is expensive! */
/* make a copy of the buffer here because strtok() will destroy it */
s = (unsigned char*) memcpy(nbuf, buf, nbytes);
@@ -106,12 +114,6 @@ int nbytes; /* size actually read */
}
}
-
- for (i = 0; i < nbytes; i++) {
- if (!isascii(buf[i]))
- return 0; /* not all ASCII */
- }
-
/* all else fails, but it is ASCII... */
ckfputs("ASCII text", stdout);
if (has_escapes) {