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