xref: /phasta/phSolver/common/posixio.cc (revision d7abaf6c7709145d1e6e6b7740bd56c3f238d064)
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 };
15 
16 void posixio_setup(phio_fp* f, char mode) {
17   *f = (phio_fp) malloc(sizeof(struct phio_file));
18   (*f)->ops = &posix_ops;
19   if(mode != 'r' && mode != 'w') {
20     fprintf(stderr, "ERROR unsupported file mode in %s on line %d"
21         "... exiting", __FILE__, __LINE__);
22     exit(EXIT_FAILURE);
23   }
24   (*f)->file = (int*) malloc(sizeof(int*));
25   (*f)->mode = mode;
26 }
27