flipbinpdb.c File Reference

#include "largefiles.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <stdio.h>

Go to the source code of this file.

Defines

#define MAP_FILE   0

Functions

int main (int argc, char *argv[])


Define Documentation

#define MAP_FILE   0

Definition at line 16 of file flipbinpdb.c.


Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 19 of file flipbinpdb.c.

References j, and MAP_FILE.

00019                                  {
00020 
00021 int fd;
00022 struct stat statbuf;
00023 off_t i, j, n;
00024 char b[8];
00025 char *d;
00026 
00027 if ( argc != 2 ) {
00028   fprintf(stderr,"This program flips byte-ordering of 8-byte doubles.\n");
00029   fprintf(stderr,"Usage: %s <filename>\n",argv[0]);
00030   exit(-1);
00031 }
00032 
00033 if ( ( fd = open(argv[1], O_RDWR) ) < 0 ) {
00034   fprintf(stderr,"Can't open %s for updating.\n",argv[1]);
00035   exit(-1);
00036 }
00037 
00038 if ( fstat(fd,&statbuf) < 0 ) {
00039   fprintf(stderr,"Can't stat %s.\n",argv[1]);
00040   exit(-1);
00041 }
00042 
00043 n = statbuf.st_size;
00044 
00045 if ( (n < 4) || ((n-4) % 24) ) {
00046   fprintf(stderr,"Size of %s is not 4 plus a multiple of 24.\n",argv[1]);
00047   exit(-1);
00048 }
00049 
00050 if ( ( d = mmap(0,n,PROT_READ|PROT_WRITE,MAP_FILE|MAP_SHARED,fd,0) )
00051                                                         == (caddr_t) -1 ) {
00052   fprintf(stderr,"Can't mmap %s.\n",argv[1]);
00053   exit(-1);
00054 }
00055 
00056 for ( j = 0; j < 4; ++j ) b[j] = d[j];
00057 for ( j = 3; j >= 0; --j, ++d ) *d = b[j];
00058 
00059 for ( i = 4; i < n; i += 8 ) {
00060   for ( j = 0; j < 8; ++j ) b[j] = d[j];
00061   for ( j = 7; j >= 0; --j, ++d ) *d = b[j];
00062 }
00063 
00064 exit(0);
00065 
00066 }


Generated on Mon Nov 20 01:17:15 2017 for NAMD by  doxygen 1.4.7