revert between 56095 -> 55830 in arch
[AROS.git] / compiler / posixc / __stdio.c
blobadbd1c02668bcf2916386af4fbec63b03c4e51ed
1 /*
2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: stdio internals
6 Lang: English
7 */
9 #include "__posixc_intbase.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 = __POSIXC_STDIO_READ;
90 break;
92 case O_WRONLY:
93 ret = __POSIXC_STDIO_WRITE;
94 break;
96 case O_RDWR:
97 ret = __POSIXC_STDIO_READ | __POSIXC_STDIO_WRITE;
98 break;
100 default:
101 errno = EINVAL;
102 return 0;
105 if (omode & O_APPEND)
106 ret |= __POSIXC_STDIO_APPEND;
108 return ret;
111 int __init_stdio(struct PosixCIntBase *PosixCIntBase)
113 struct PosixCBase *PosixCBase = (struct PosixCBase *)PosixCIntBase;
114 NEWLIST(&PosixCIntBase->stdio_files);
118 !(PosixCBase->_stdin = fdopen(STDIN_FILENO, NULL)) ||
119 !(PosixCBase->_stdout = fdopen(STDOUT_FILENO, NULL)) ||
120 !(PosixCBase->_stderr = fdopen(STDERR_FILENO, NULL))
123 SetIoErr(ERROR_NO_FREE_STORE);
124 return 0;
127 return 1;
130 ADD2OPENLIB(__init_stdio, 5);