NAMD
Macros | Functions
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>
#include <stdlib.h>

Go to the source code of this file.

Macros

#define MAP_FILE   0
 

Functions

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

Macro Definition Documentation

#define MAP_FILE   0

Definition at line 17 of file flipbinpdb.c.

Referenced by main().

Function Documentation

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

Definition at line 20 of file flipbinpdb.c.

References MAP_FILE.

20  {
21 
22 int fd;
23 struct stat statbuf;
24 off_t i, j, n;
25 char b[8];
26 char *d;
27 
28 if ( argc != 2 ) {
29  fprintf(stderr,"This program flips byte-ordering of 8-byte doubles.\n");
30  fprintf(stderr,"Usage: %s <filename>\n",argv[0]);
31  exit(-1);
32 }
33 
34 if ( ( fd = open(argv[1], O_RDWR) ) < 0 ) {
35  fprintf(stderr,"Can't open %s for updating.\n",argv[1]);
36  exit(-1);
37 }
38 
39 if ( fstat(fd,&statbuf) < 0 ) {
40  fprintf(stderr,"Can't stat %s.\n",argv[1]);
41  exit(-1);
42 }
43 
44 n = statbuf.st_size;
45 
46 if ( (n < 4) || ((n-4) % 24) ) {
47  fprintf(stderr,"Size of %s is not 4 plus a multiple of 24.\n",argv[1]);
48  exit(-1);
49 }
50 
51 if ( ( d = mmap(0,n,PROT_READ|PROT_WRITE,MAP_FILE|MAP_SHARED,fd,0) )
52  == (caddr_t) -1 ) {
53  fprintf(stderr,"Can't mmap %s.\n",argv[1]);
54  exit(-1);
55 }
56 
57 for ( j = 0; j < 4; ++j ) b[j] = d[j];
58 for ( j = 3; j >= 0; --j, ++d ) *d = b[j];
59 
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];
63 }
64 
65 exit(0);
66 
67 }
#define MAP_FILE
Definition: flipbinpdb.c:17