summaryrefslogtreecommitdiffstats
path: root/pintos-progos/examples/cat.c
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2012-03-26 12:54:45 +0200
committermanuel <manuel@mausz.at>2012-03-26 12:54:45 +0200
commitb5f0874cd96ee2a62aabc645b9626c2749cb6a01 (patch)
tree1262e4bbe0634de6650be130c36e0538240f4cbf /pintos-progos/examples/cat.c
downloadprogos-b5f0874cd96ee2a62aabc645b9626c2749cb6a01.tar.gz
progos-b5f0874cd96ee2a62aabc645b9626c2749cb6a01.tar.bz2
progos-b5f0874cd96ee2a62aabc645b9626c2749cb6a01.zip
initial pintos checkin
Diffstat (limited to 'pintos-progos/examples/cat.c')
-rw-r--r--pintos-progos/examples/cat.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/pintos-progos/examples/cat.c b/pintos-progos/examples/cat.c
new file mode 100644
index 0000000..c8d229d
--- /dev/null
+++ b/pintos-progos/examples/cat.c
@@ -0,0 +1,34 @@
1/* cat.c
2
3 Prints files specified on command line to the console. */
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 bytes_read = read (fd, buffer, sizeof buffer);
27 if (bytes_read == 0)
28 break;
29 write (STDOUT_FILENO, buffer, bytes_read);
30 }
31 close (fd);
32 }
33 return success ? EXIT_SUCCESS : EXIT_FAILURE;
34}