wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <string.h> |
| 4 | #include <unistd.h> |
| 5 | |
| 6 | #ifndef BUFSIZ |
| 7 | # define BUFSIZ 4096 |
| 8 | #endif |
| 9 | |
| 10 | #undef BUFSIZ |
| 11 | # define BUFSIZ 64 |
| 12 | int main (void) |
| 13 | { |
| 14 | short ibuff[BUFSIZ], obuff[BUFSIZ]; |
| 15 | int rc, i, len; |
| 16 | |
| 17 | while ((rc = read (0, ibuff, sizeof (ibuff))) > 0) { |
| 18 | memset (obuff, 0, sizeof (obuff)); |
| 19 | for (i = 0; i < (rc + 1) / 2; i++) { |
| 20 | obuff[i] = ibuff[i ^ 1]; |
| 21 | } |
| 22 | |
| 23 | len = (rc + 1) & ~1; |
| 24 | |
| 25 | if (write (1, obuff, len) != len) { |
| 26 | perror ("read error"); |
| 27 | return (EXIT_FAILURE); |
| 28 | } |
| 29 | |
| 30 | memset (ibuff, 0, sizeof (ibuff)); |
| 31 | } |
| 32 | |
| 33 | if (rc < 0) { |
| 34 | perror ("read error"); |
| 35 | return (EXIT_FAILURE); |
| 36 | } |
| 37 | return (EXIT_SUCCESS); |
| 38 | } |