Upgraded GRUB2 to 2.00 release.
[AROS.git] / compiler / clib / __stdio.c
blobe49bf30ac618ddf8660a091729c29005abb647ce
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: stdio internals
6 Lang: English
7 */
9 #include "__arosc_privdata.h"
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <fcntl.h>
14 #include <unistd.h>
15 #include <errno.h>
17 #include <exec/lists.h>
18 #include <dos/dos.h>
19 #include <proto/exec.h>
20 #include <proto/dos.h>
21 #include <aros/symbolsets.h>
22 #include <aros/debug.h>
23 #include "__stdio.h"
25 int __smode2oflags(const char *mode)
27 int ret = -1;
28 int theresb = 0;
30 switch (*mode++)
32 case 'r':
33 ret = O_RDONLY;
34 break;
36 case 'w':
37 ret = O_WRONLY | O_CREAT | O_TRUNC;
38 break;
40 case 'a':
41 ret = O_WRONLY | O_CREAT | O_APPEND;
42 break;
44 default:
45 errno = EINVAL;
46 return -1;
49 if (*mode == 'b')
51 theresb = 1;
52 mode++;
54 else if (*mode == 't')
56 // Silently ignore 't' (=text).
57 // It's deprecated, but it's still in some sources,
58 // and on other platforms they can compiled without problems.
59 mode++;
62 if (*mode == '+')
64 ret = O_RDWR | (ret & ~O_ACCMODE);
65 mode++;
68 if (*mode == 'b' && !theresb)
70 mode++;
73 if (*mode != '\0')
75 errno = EINVAL;
76 return -1;
79 return ret;
82 int __oflags2sflags(int omode)
84 int ret;
86 switch (omode & O_ACCMODE)
88 case O_RDONLY:
89 ret = _STDIO_READ;
90 break;
92 case O_WRONLY:
93 ret = _STDIO_WRITE;
94 break;
96 case O_RDWR:
97 ret = _STDIO_READ | _STDIO_WRITE;
98 break;
100 default:
101 errno = EINVAL;
102 return 0;
105 if (omode & O_APPEND)
106 ret |= _STDIO_APPEND;
108 return ret;
111 int __init_stdio(struct aroscbase *aroscbase)
113 NEWLIST(&aroscbase->acb_stdio_files);
117 !(stdin = fdopen(STDIN_FILENO, NULL)) ||
118 !(stdout = fdopen(STDOUT_FILENO, NULL)) ||
119 !(stderr = fdopen(STDERR_FILENO, NULL))
122 SetIoErr(ERROR_NO_FREE_STORE);
123 return 0;
126 return 1;
129 ADD2OPENLIB(__init_stdio, 5);