define __KERNEL_STRICT_NAMES to avoid inclusion of kernel types on systems that carry...
[cake.git] / compiler / clib / __stdio.c
blobbca7a8d62e8da7753ca206adc51b4dd72e37efa3
1 /*
2 Copyright © 1995-2001, 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 "__open.h"
24 #include "__stdio.h"
26 int __smode2oflags(const char *mode)
28 int ret = -1;
29 int theresb = 0;
31 switch (*mode++)
33 case 'r':
34 ret = O_RDONLY;
35 break;
37 case 'w':
38 ret = O_WRONLY | O_CREAT | O_TRUNC;
39 break;
41 case 'a':
42 ret = O_WRONLY | O_CREAT | O_APPEND;
43 break;
45 default:
46 errno = EINVAL;
47 return -1;
50 if (*mode == 'b')
52 theresb = 1;
53 mode++;
55 else if (*mode == 't')
57 // Silently ignore 't' (=text).
58 // It's deprecated, but it's still in some sources,
59 // and on other platforms they can compiled without problems.
60 mode++;
63 if (*mode == '+')
65 ret = O_RDWR | (ret & ~O_ACCMODE);
66 mode++;
69 if (*mode == 'b' && !theresb)
71 mode++;
74 if (*mode != '\0')
76 errno = EINVAL;
77 return -1;
80 return ret;
83 int __oflags2sflags(int omode)
85 int ret;
87 switch (omode & O_ACCMODE)
89 case O_RDONLY:
90 ret = _STDIO_READ;
91 break;
93 case O_WRONLY:
94 ret = _STDIO_WRITE;
95 break;
97 case O_RDWR:
98 ret = _STDIO_READ | _STDIO_WRITE;
99 break;
101 default:
102 errno = EINVAL;
103 return 0;
106 if (omode & O_APPEND)
107 ret |= _STDIO_APPEND;
109 return ret;
112 int __init_stdio(void)
114 NEWLIST(&__stdio_files);
118 !(stdin = fdopen(STDIN_FILENO, NULL)) ||
119 !(stdout = fdopen(STDOUT_FILENO, NULL)) ||
120 !(stderr = fdopen(STDERR_FILENO, NULL))
123 SetIoErr(ERROR_NO_FREE_STORE);
124 return 0;
127 return 1;
130 ADD2INIT(__init_stdio, 5);