Adding upstream version 6.02~pre8+dfsg.
[syslinux-debian/hramrach.git] / com32 / lib / sys / zfopen.c
blob752aaf427b601b468cc79d1d4fb97d762645c8f5
1 /*
2 * zfopen.c
3 */
5 #include <stdio.h>
6 #include <unistd.h>
7 #include <fcntl.h>
8 #include <syslinux/zio.h>
10 FILE *zfopen(const char *file, const char *mode)
12 int flags = O_RDONLY;
13 int plus = 0;
14 int fd;
16 while (*mode) {
17 switch (*mode) {
18 case 'r':
19 flags = O_RDONLY;
20 break;
21 case 'w':
22 flags = O_WRONLY | O_CREAT | O_TRUNC;
23 break;
24 case 'a':
25 flags = O_WRONLY | O_CREAT | O_APPEND;
26 break;
27 case '+':
28 plus = 1;
29 break;
31 mode++;
34 if (plus) {
35 flags = (flags & ~(O_RDONLY | O_WRONLY)) | O_RDWR;
38 fd = zopen(file, flags, 0666);
40 if (fd < 0)
41 return NULL;
42 else
43 return fdopen(fd, mode);