Add some more examples.
[pintos-anon] / src / examples / hex-dump.c
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   int i;
12   
13   for (i = 1; i < argc; i++) 
14     {
15       int fd = open (argv[i]);
16       if (fd < 0) 
17         {
18           printf ("%s: open failed\n", argv[i]);
19           continue;
20         }
21       for (;;) 
22         {
23           char buffer[1024];
24           int pos = tell (fd);
25           int bytes_read = read (fd, buffer, sizeof buffer);
26           if (bytes_read == 0)
27             break;
28           hex_dump (pos, buffer, bytes_read, true);
29         }
30       close (fd);
31     }
32   return 0;
33 }