Adding upstream version 3.50~pre5.
[syslinux-debian/hramrach.git] / com32 / lib / fopen.c
blobbf1e452f9f3232b818688ce40aaefb54c44494c9
1 /*
2 * fopen.c
3 */
5 #include <stdio.h>
6 #include <unistd.h>
7 #include <fcntl.h>
9 FILE *fopen(const char *file, const char *mode)
11 int flags = O_RDONLY;
12 int plus = 0;
13 int fd;
15 while ( *mode ) {
16 switch ( *mode ) {
17 case 'r':
18 flags = O_RDONLY;
19 break;
20 case 'w':
21 flags = O_WRONLY|O_CREAT|O_TRUNC;
22 break;
23 case 'a':
24 flags = O_WRONLY|O_CREAT|O_APPEND;
25 break;
26 case '+':
27 plus = 1;
28 break;
30 mode++;
33 if ( plus ) {
34 flags = (flags & ~(O_RDONLY|O_WRONLY)) | O_RDWR;
37 fd = open(file, flags, 0666);
39 if ( fd < 0 )
40 return NULL;
41 else
42 return fdopen(fd, mode);