Porting current working set from CVS.
[fw/pdclib] / platform / example / functions / _PDCLIB / open.c
1 /* $Id$ */
2
3 /* Release $Name$ */
4
5 /* _PDCLIB_open( char const * const, int )
6
7    This file is part of the Public Domain C Library (PDCLib).
8    Permission is granted to use, modify, and / or redistribute at will.
9 */
10
11 /* This is an example implementation of _PDCLIB_open() fit for use with POSIX
12    kernels.
13 */
14
15 #include <stdio.h>
16
17 #ifndef REGTEST
18 #include <_PDCLIB_glue.h>
19
20 #include <sys/types.h>
21 #include <sys/stat.h>
22 #include <fcntl.h>
23 #include <unistd.h>
24
25 _PDCLIB_fd_t _PDCLIB_open( char const * const filename, int mode )
26 {
27     int osmode = 0;
28     if ( mode & _PDCLIB_FRW ) osmode |= O_RDWR;
29     if ( mode & ( _PDCLIB_FWRITE | _PDCLIB_FAPPEND ) ) osmode |= O_CREAT;
30     if ( mode & _PDCLIB_FWRITE ) osmode |= O_TRUNC;
31     if ( mode & _PDCLIB_FAPPEND ) osmode |= O_APPEND;
32     if ( ( mode & _PDCLIB_FREAD ) && ! ( mode & _PDCLIB_FRW ) ) osmode |= O_RDONLY;
33     return open( filename, osmode );
34 }
35
36 #endif
37
38 #ifdef TEST
39 #include <_PDCLIB_test.h>
40
41 int main( void )
42 {
43     TESTCASE( NO_TESTDRIVER );
44     return TEST_RESULTS;
45 }
46
47 #endif