Magellan Linux

Contents of /trunk/mkinitrd-magellan/klibc/usr/klibc/fopen.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 532 - (show annotations) (download)
Sat Sep 1 22:45:15 2007 UTC (16 years, 8 months ago) by niro
File MIME type: text/plain
File size: 659 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd

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 int flags = O_RDONLY;
14 int plus = 0;
15
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;
30 }
31 }
32
33 if (plus) {
34 flags = (flags & ~(O_RDONLY | O_WRONLY)) | O_RDWR;
35 }
36
37 /* Note: __create_file(-1) == NULL, so this is safe */
38 return __create_file(open(file, flags, 0666));
39 }