1 /* _PDCLIB_open(_PDCLIB_fd_t*, const _PDCLIB_fileops_t**,
2 char const*, unsigned int)
4 This file is part of the Public Domain C Library (PDCLib).
5 Permission is granted to use, modify, and / or redistribute at will.
8 #include <_PDCLIB_glue.h>
9 #include <_PDCLIB_io.h>
12 extern const _PDCLIB_fileops_t _PDCLIB_fileops;
15 _PDCLIB_fd_t* fd, const _PDCLIB_fileops_t** ops,
16 char const * filename, unsigned int mode )
19 switch ( mode & ( _PDCLIB_FREAD | _PDCLIB_FWRITE | _PDCLIB_FAPPEND | _PDCLIB_FRW ) )
21 case _PDCLIB_FREAD: /* "r" */
24 case _PDCLIB_FWRITE: /* "w" */
25 osmode = O_WRONLY | O_CREAT | O_TRUNC;
27 case _PDCLIB_FAPPEND: /* "a" */
28 osmode = O_WRONLY | O_APPEND | O_CREAT;
30 case _PDCLIB_FREAD | _PDCLIB_FRW: /* "r+" */
33 case _PDCLIB_FWRITE | _PDCLIB_FRW: /* "w+" */
34 osmode = O_RDWR | O_CREAT | O_TRUNC;
36 case _PDCLIB_FAPPEND | _PDCLIB_FRW: /* "a+" */
37 osmode = O_RDWR | O_APPEND | O_CREAT;
39 default: /* Invalid mode */
43 fd->sval = open(filename, osmode,
44 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
49 *ops = &_PDCLIB_fileops;
55 #include <_PDCLIB_test.h>