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.

Functions

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

Function Documentation

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

Definition at line 20 of file flipbinpdb.c.

References j, and MAP_FILE.

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


Generated on 15 Sep 2019 for NAMD by  doxygen 1.6.1