diff options
| author | manuel <manuel@mausz.at> | 2012-03-27 11:51:08 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2012-03-27 11:51:08 +0200 |
| commit | 4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b (patch) | |
| tree | 868c52e06f207b5ec8a3cc141f4b8b2bdfcc165c /examples/lineup.c | |
| parent | eae0bd57f0a26314a94785061888d193d186944a (diff) | |
| download | progos-4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b.tar.gz progos-4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b.tar.bz2 progos-4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b.zip | |
reorganize file structure to match the upstream requirements
Diffstat (limited to 'examples/lineup.c')
| -rw-r--r-- | examples/lineup.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/examples/lineup.c b/examples/lineup.c new file mode 100644 index 0000000..60402d0 --- /dev/null +++ b/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 | |||
| 14 | int | ||
| 15 | main (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 | } | ||
