aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2016-02-13 09:50:20 -0800
committerRob Landley <rob@landley.net>2016-02-14 12:36:40 -0600
commit9502a77ea0a16c395407f31af0bbb0afd0680adb (patch)
tree3310cc3088d787fb9fbe63ee7c2ce22bceb0048b /lib
parent09d95477765d3941aacb61c97f76ee94301b8faa (diff)
downloadtoybox-9502a77ea0a16c395407f31af0bbb0afd0680adb.tar.gz
Implement file(1).
Unlike the POSIX file(1), there's no magic file here, just hard-coded common (non-obsolete) file formats. Personally most of my use of file(1) is as a one-line readelf(1) summarizer, so although I assume a full POSIX file(1) is out of scope (because just the database would likely be larger than all the rest of toybox), a subset that only supports in-use file types actually covers most of the use cases I encounter personally. Also fix peek_be/peek_le.
Diffstat (limited to 'lib')
-rw-r--r--lib/lib.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/lib/lib.c b/lib/lib.c
index 681d4d23..e80b8b12 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -508,8 +508,7 @@ int64_t peek_le(void *ptr, unsigned size)
char *c = ptr;
int i;
- for (i=0; i<size; i++) ret |= ((int64_t)c[i])<<i;
-
+ for (i=0; i<size; i++) ret |= ((int64_t)c[i])<<(i*8);
return ret;
}
@@ -517,9 +516,9 @@ int64_t peek_be(void *ptr, unsigned size)
{
int64_t ret = 0;
char *c = ptr;
+ int i;
- while (size--) ret = (ret<<8)|c[size];
-
+ for (i=0; i<size; i++) ret = (ret<<8)|(c[i]&0xff);
return ret;
}