summaryrefslogtreecommitdiffstats
path: root/pintos-progos/examples/lineup.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/lineup.c
downloadprogos-b5f0874cd96ee2a62aabc645b9626c2749cb6a01.tar.gz
progos-b5f0874cd96ee2a62aabc645b9626c2749cb6a01.tar.bz2
progos-b5f0874cd96ee2a62aabc645b9626c2749cb6a01.zip
initial pintos checkin
Diffstat (limited to 'pintos-progos/examples/lineup.c')
-rw-r--r--pintos-progos/examples/lineup.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/pintos-progos/examples/lineup.c b/pintos-progos/examples/lineup.c
new file mode 100644
index 0000000..60402d0
--- /dev/null
+++ b/pintos-progos/examples/lineup.c
@@ -0,0 +1,46 @@
1/* lineup.c
2
3 Converts a file to uppercase in-place.
4
5 Incidentally, another way to do this while avoiding the seeks
6 would be to open the input file, then remove() it and reopen
7 it under another handle. Because of Unix deletion semantics
8 this works fine. */
9
10#include <ctype.h>
11#include <stdio.h>
12#include <syscall.h>
13
14int
15main (int argc, char *argv[])
16{
17 char buf[1024];
18 int handle;
19
20 if (argc != 2)
21 exit (1);
22
23 handle = open (argv[1]);
24 if (handle < 0)
25 exit (2);
26
27 for (;;)
28 {
29 int n, i;
30
31 n = read (handle, buf, sizeof buf);
32 if (n <= 0)
33 break;
34
35 for (i = 0; i < n; i++)
36 buf[i] = toupper ((unsigned char) buf[i]);
37
38 seek (handle, tell (handle) - n);
39 if (write (handle, buf, n) != n)
40 printf ("write failed\n");
41 }
42
43 close (handle);
44
45 return EXIT_SUCCESS;
46}