aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2016-02-29 19:35:13 -0800
committerRob Landley <rob@landley.net>2016-03-02 22:25:36 -0600
commitffc6fbbde3eeca29d1eb3470610eb7ae5b9025f1 (patch)
tree836a56b6f2614dd6f2c861a8448a6a47c6f5f0a3 /toys
parent5231bb553d5e2c04818f6603f30a36653d914881 (diff)
downloadtoybox-ffc6fbbde3eeca29d1eb3470610eb7ae5b9025f1.tar.gz
Fix file for Java class files, improve script detection, and add tests.
Diffstat (limited to 'toys')
-rw-r--r--toys/pending/file.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/toys/pending/file.c b/toys/pending/file.c
index e4820a3b..fbff5867 100644
--- a/toys/pending/file.c
+++ b/toys/pending/file.c
@@ -170,7 +170,7 @@ static void do_regular_file(int fd, char *name)
// https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html
else if (len>8 && strstart(&s, "\xca\xfe\xba\xbe"))
xprintf("Java class file, version %d.%d\n",
- (int)peek_be(s+6, 2), (int)peek_be(s, 2));
+ (int)peek_be(s+2, 2), (int)peek_be(s, 2));
// https://people.freebsd.org/~kientzle/libarchive/man/cpio.5.txt
// the lengths for cpio are size of header + 9 bytes, since any valid
@@ -204,6 +204,9 @@ static void do_regular_file(int fd, char *name)
// If shell script, report which interpreter
if (len>3 && strstart(&s, "#!")) {
+ // Whitespace is allowed between the #! and the interpreter
+ while (isspace(*s)) s++;
+ if (strstart(&s, "/usr/bin/env")) while (isspace(*s)) s++;
for (what = s; (s-toybuf)<len && !isspace(*s); s++);
strcpy(s, " script");