The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1 | #include <debug.h> |
| 2 | #include <unistd.h> |
| 3 | |
| 4 | #include <stdio.h> |
| 5 | #include <sys/types.h> |
| 6 | #include <sys/stat.h> |
| 7 | #include <fcntl.h> |
| 8 | #include <string.h> |
| 9 | #include <errno.h> |
| 10 | |
| 11 | int |
| 12 | main(int argc, char **argv) |
| 13 | { |
| 14 | char *fname; |
| 15 | int fd; |
| 16 | char magic[4]; |
| 17 | |
| 18 | argc--, argv++; |
| 19 | FAILIF(argc != 1, "Expecting a file name!\n"); |
| 20 | fname = *argv; |
| 21 | |
| 22 | fd = open(fname, O_RDONLY); |
| 23 | FAILIF(fd < 0, "Error opening %s for reading: %s (%d)!\n", |
| 24 | fname, strerror(errno), errno); |
| 25 | |
| 26 | FAILIF(4 != read(fd, magic, 4), |
| 27 | "Could not read first 4 bytes from %s: %s (%d)!\n", |
| 28 | fname, strerror(errno), errno); |
| 29 | |
| 30 | if (magic[0] != 0x7f) return 1; |
| 31 | if (magic[1] != 'E') return 1; |
| 32 | if (magic[2] != 'L') return 1; |
| 33 | if (magic[3] != 'F') return 1; |
| 34 | |
| 35 | return 0; |
| 36 | } |