diff options
| author | manuel <manuel@mausz.at> | 2012-03-27 11:51:08 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2012-03-27 11:51:08 +0200 |
| commit | 4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b (patch) | |
| tree | 868c52e06f207b5ec8a3cc141f4b8b2bdfcc165c /examples/hex-dump.c | |
| parent | eae0bd57f0a26314a94785061888d193d186944a (diff) | |
| download | progos-4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b.tar.gz progos-4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b.tar.bz2 progos-4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b.zip | |
reorganize file structure to match the upstream requirements
Diffstat (limited to 'examples/hex-dump.c')
| -rw-r--r-- | examples/hex-dump.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/examples/hex-dump.c b/examples/hex-dump.c new file mode 100644 index 0000000..ee313f2 --- /dev/null +++ b/examples/hex-dump.c | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | /* hex-dump.c | ||
| 2 | |||
| 3 | Prints files specified on command line to the console in hex. */ | ||
| 4 | |||
| 5 | #include <stdio.h> | ||
| 6 | #include <syscall.h> | ||
| 7 | |||
| 8 | int | ||
| 9 | main (int argc, char *argv[]) | ||
| 10 | { | ||
| 11 | bool success = true; | ||
| 12 | int i; | ||
| 13 | |||
| 14 | for (i = 1; i < argc; i++) | ||
| 15 | { | ||
| 16 | int fd = open (argv[i]); | ||
| 17 | if (fd < 0) | ||
| 18 | { | ||
| 19 | printf ("%s: open failed\n", argv[i]); | ||
| 20 | success = false; | ||
| 21 | continue; | ||
| 22 | } | ||
| 23 | for (;;) | ||
| 24 | { | ||
| 25 | char buffer[1024]; | ||
| 26 | int pos = tell (fd); | ||
| 27 | int bytes_read = read (fd, buffer, sizeof buffer); | ||
| 28 | if (bytes_read == 0) | ||
| 29 | break; | ||
| 30 | hex_dump (pos, buffer, bytes_read, true); | ||
| 31 | } | ||
| 32 | close (fd); | ||
| 33 | } | ||
| 34 | return success ? EXIT_SUCCESS : EXIT_FAILURE; | ||
| 35 | } | ||
