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>
13 extern const _PDCLIB_fileops_t _PDCLIB_fileops;
16 _PDCLIB_fd_t* fd, const _PDCLIB_fileops_t** ops,
17 char const * filename, unsigned int mode )
20 switch ( mode & ( _PDCLIB_FREAD | _PDCLIB_FWRITE | _PDCLIB_FAPPEND | _PDCLIB_FRW ) )
22 case _PDCLIB_FREAD: /* "r" */
25 case _PDCLIB_FWRITE: /* "w" */
26 osmode = O_WRONLY | O_CREAT | O_TRUNC;
28 case _PDCLIB_FAPPEND: /* "a" */
29 osmode = O_WRONLY | O_APPEND | O_CREAT;
31 case _PDCLIB_FREAD | _PDCLIB_FRW: /* "r+" */
34 case _PDCLIB_FWRITE | _PDCLIB_FRW: /* "w+" */
35 osmode = O_RDWR | O_CREAT | O_TRUNC;
37 case _PDCLIB_FAPPEND | _PDCLIB_FRW: /* "a+" */
38 osmode = O_RDWR | O_APPEND | O_CREAT;
40 default: /* Invalid mode */
44 fd->sval = open(filename, osmode, 0664);
49 *ops = &_PDCLIB_fileops;
55 #include <_PDCLIB_test.h>