summaryrefslogtreecommitdiffstats
path: root/examples/cat.c
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2012-03-27 11:51:08 +0200
committermanuel <manuel@mausz.at>2012-03-27 11:51:08 +0200
commit4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b (patch)
tree868c52e06f207b5ec8a3cc141f4b8b2bdfcc165c /examples/cat.c
parenteae0bd57f0a26314a94785061888d193d186944a (diff)
downloadprogos-4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b.tar.gz
progos-4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b.tar.bz2
progos-4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b.zip
reorganize file structure to match the upstream requirements
Diffstat (limited to 'examples/cat.c')
-rw-r--r--examples/cat.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/examples/cat.c b/examples/cat.c
new file mode 100644
index 0000000..c8d229d
--- /dev/null
+++ b/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}