source: bootcd/isolinux/syslinux-6.03/com32/lib/fopen.c

Last change on this file was e16e8f2, checked in by Edwin Eefting <edwin@datux.nl>, 3 years ago

bootstuff

  • Property mode set to 100644
File size: 636 bytes
Line 
1/*
2 * fopen.c
3 */
4
5#include <stdio.h>
6#include <unistd.h>
7#include <fcntl.h>
8
9FILE *fopen(const char *file, const char *mode)
10{
11    int flags = O_RDONLY;
12    int plus = 0;
13    int fd;
14
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;
29        }
30        mode++;
31    }
32
33    if (plus) {
34        flags = (flags & ~(O_RDONLY | O_WRONLY)) | O_RDWR;
35    }
36
37    fd = open(file, flags, 0666);
38
39    if (fd < 0)
40        return NULL;
41    else
42        return fdopen(fd, mode);
43}
Note: See TracBrowser for help on using the repository browser.