to make u-boot work for fat32 filesystem
[jz_uboot.git] / tools / inca-swap-bytes.c
blob3a6d82d54a06f68753e923907688720f8d9dac5a
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <unistd.h>
6 #ifndef BUFSIZ
7 # define BUFSIZ 4096
8 #endif
10 #undef BUFSIZ
11 # define BUFSIZ 64
12 int main (void)
14 short ibuff[BUFSIZ], obuff[BUFSIZ];
15 int rc, i, len;
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];
23 len = (rc + 1) & ~1;
25 if (write (1, obuff, len) != len) {
26 perror ("read error");
27 return (EXIT_FAILURE);
30 memset (ibuff, 0, sizeof (ibuff));
33 if (rc < 0) {
34 perror ("read error");
35 return (EXIT_FAILURE);
37 return (EXIT_SUCCESS);