20 int main(
int argc,
char *argv[]) {
29 fprintf(stderr,
"This program flips byte-ordering of 8-byte doubles.\n");
30 fprintf(stderr,
"Usage: %s <filename>\n",argv[0]);
34 if ( ( fd = open(argv[1], O_RDWR) ) < 0 ) {
35 fprintf(stderr,
"Can't open %s for updating.\n",argv[1]);
39 if ( fstat(fd,&statbuf) < 0 ) {
40 fprintf(stderr,
"Can't stat %s.\n",argv[1]);
46 if ( (n < 4) || ((n-4) % 24) ) {
47 fprintf(stderr,
"Size of %s is not 4 plus a multiple of 24.\n",argv[1]);
51 if ( ( d = mmap(0,n,PROT_READ|PROT_WRITE,
MAP_FILE|MAP_SHARED,fd,0) )
53 fprintf(stderr,
"Can't mmap %s.\n",argv[1]);
57 for ( j = 0; j < 4; ++j ) b[j] = d[j];
58 for ( j = 3; j >= 0; --j, ++d ) *d = b[j];
60 for ( i = 4; i < n; i += 8 ) {
61 for ( j = 0; j < 8; ++j ) b[j] = d[j];
62 for ( j = 7; j >= 0; --j, ++d ) *d = b[j];
int main(int argc, char *argv[])