3 * Copyright (C) 2007, 2008, 2009, 2010 Sebastien Bourdeauducq
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 int main(int argc
, char *argv
[])
30 fprintf(stderr
, "Usage: byteswap <infile> <outfile>\n");
33 fdi
= fopen(argv
[1], "rb");
35 perror("Unable to open input file");
38 fdo
= fopen(argv
[2], "w");
40 perror("Unable to open output file");
45 if(fread(&wi
, 2, 1, fdi
) <= 0) break;
50 /* comment out the next line on big endian machines! */
51 wo
= ((wo
& 0x00ff) << 8) | ((wo
& 0xff00) >> 8);
52 fwrite(&wo
, 2, 1, fdo
);
55 if(fclose(fdo
) != 0) {
56 perror("Unable to close output file");