Root/
Source at commit 1308 created 12 years 8 months ago. By meklort, Add a few placeholders for file io | |
---|---|
1 | /*␊ |
2 | * fopen.c␊ |
3 | */␊ |
4 | ␊ |
5 | #include <stdio.h>␊ |
6 | #include <unistd.h>␊ |
7 | //#include <fcntl.h>␊ |
8 | ␊ |
9 | /* This depends on O_RDONLY == 0, O_WRONLY == 1, O_RDWR == 2 */␊ |
10 | ␊ |
11 | FILE *fopen(const char *file, const char *mode)␊ |
12 | {␊ |
13 | ␉printf("WARNING: fopen unimplimented.\n");␊ |
14 | ␉return NULL;␊ |
15 | #if 0␊ |
16 | ␉int flags = O_RDONLY;␊ |
17 | ␉int plus = 0;␊ |
18 | ␊ |
19 | ␉while (*mode) {␊ |
20 | ␉␉switch (*mode++) {␊ |
21 | ␉␉case 'r':␊ |
22 | ␉␉␉flags = O_RDONLY;␊ |
23 | ␉␉␉break;␊ |
24 | ␉␉case 'w':␊ |
25 | ␉␉␉flags = O_WRONLY | O_CREAT | O_TRUNC;␊ |
26 | ␉␉␉break;␊ |
27 | ␉␉case 'a':␊ |
28 | ␉␉␉flags = O_WRONLY | O_CREAT | O_APPEND;␊ |
29 | ␉␉␉break;␊ |
30 | ␉␉case '+':␊ |
31 | ␉␉␉plus = 1;␊ |
32 | ␉␉␉break;␊ |
33 | ␉␉}␊ |
34 | ␉}␊ |
35 | ␊ |
36 | ␉if (plus) {␊ |
37 | ␉␉flags = (flags & ~(O_RDONLY | O_WRONLY)) | O_RDWR;␊ |
38 | ␉}␊ |
39 | ␊ |
40 | ␉/* Note: __create_file(-1) == NULL, so this is safe */␊ |
41 | ␉return __create_file(open(file, flags, 0666));␊ |
42 | #endif␊ |
43 | }␊ |
44 |