xref: /phasta/phSolver/common/posixio.cc (revision 7acde132a6def0fe2daaec0d1a712dff0e5c6636)
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "posixio.h"
4 #include "phio_posix.h"
5 #include "phio_base.h"
6 
7 static struct phio_ops posix_ops = {
8   posix_openfile,
9   posix_closefile,
10   posix_readheader,
11   posix_writeheader,
12   posix_readdatablock,
13   posix_writedatablock,
14   posix_constructname
15 };
16 
posixio_setup(phio_fp * f,char mode)17 void posixio_setup(phio_fp* f, char mode) {
18   *f = (phio_fp) malloc(sizeof(struct phio_file));
19   (*f)->ops = &posix_ops;
20   if(mode != 'r' && mode != 'w') {
21     fprintf(stderr, "ERROR unsupported file mode in %s on line %d"
22         "... exiting", __FILE__, __LINE__);
23     exit(EXIT_FAILURE);
24   }
25   (*f)->file = (int*) malloc(sizeof(int*));
26   (*f)->mode = mode;
27 }
28