PKUOS - Pintos
Pintos source browser for PKU Operating System course
hex-dump.c
Go to the documentation of this file.
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
8int
9main (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}
int main(int argc, char *argv[])
hex-dump.c
Definition: hex-dump.c:9
static struct intq buffer
Stores keys from the keyboard and serial port.
Definition: input.c:7
int printf(const char *format,...)
Writes formatted output to the console.
Definition: stdio.c:79
void hex_dump(uintptr_t ofs, const void *buf_, size_t size, bool ascii)
Dumps the SIZE bytes in BUF to the console as hex bytes arranged 16 per line.
Definition: stdio.c:593
void close(int fd)
Definition: syscall.c:139
int open(const char *file)
Definition: syscall.c:103
unsigned tell(int fd)
Definition: syscall.c:133
int read(int fd, void *buffer, unsigned size)
Definition: syscall.c:115
#define EXIT_SUCCESS
Typical return values from main() and arguments to exit().
Definition: syscall.h:19
#define EXIT_FAILURE
Unsuccessful execution.
Definition: syscall.h:20