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