#include #include #define BLOCK_SIZE 0x1000 unsigned char data[BLOCK_SIZE]; unsigned char out_data[BLOCK_SIZE]; #define SWAP_INT(x) ((((unsigned int)x & 0xFF) << 24) |(((unsigned int)x & 0xFF00) << 8) |(((unsigned int)x & 0xFF0000) >> 8) | (((unsigned int)x & 0xFF000000) >> 24)) int main(int argc, char * argv[]) { FILE * input; FILE * output; size_t read_count; size_t write_count; unsigned long * walker; unsigned long * out_walker; /* uncomment this if compiling on cygwin */ #if 0 if(-1 == setmode(fileno(stdin), O_BINARY)){ perror("Cannot set stdin to binary mode"); return -1; } if(-1 == setmode(fileno(stdout), O_BINARY)){ perror("Cannot set stdout to binary mode"); return -1; } #endif do{ read_count = fread(data, 1, BLOCK_SIZE, stdin); if((0 != (read_count & 3))&&(0 != read_count)){ fprintf(stderr, "Input size must be divisible by 4!\n"); return -1; } if(read_count != 0){ walker = (unsigned long*)data; out_walker = (unsigned long*)out_data; while(walker != (unsigned long*)(&data[BLOCK_SIZE])) { *out_walker = SWAP_INT(*walker); out_walker++; walker++; } write_count = fwrite(out_data, 1, read_count, stdout); if(read_count != write_count){ perror("Unable to write data"); return -1; } } }while(BLOCK_SIZE == read_count); return 0; }