add a missing section header table index conversion
[tangerine.git] / compiler / clib / __stdio.c
blobad3e3ea25160a73e987ca0e5f959eaa18d51cad6
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++;
56 if (*mode == '+')
58 ret = O_RDWR | (ret & ~O_ACCMODE);
59 mode++;
62 if (*mode == 'b' && !theresb)
64 mode++;
67 if (*mode != '\0')
69 errno = EINVAL;
70 return -1;
73 return ret;
76 int __oflags2sflags(int omode)
78 int ret;
80 switch (omode & O_ACCMODE)
82 case O_RDONLY:
83 ret = _STDIO_READ;
84 break;
86 case O_WRONLY:
87 ret = _STDIO_WRITE;
88 break;
90 case O_RDWR:
91 ret = _STDIO_READ | _STDIO_WRITE;
92 break;
94 default:
95 errno = EINVAL;
96 return 0;
99 if (omode & O_APPEND)
100 ret |= _STDIO_APPEND;
102 return ret;
105 int __init_stdio(void)
107 NEWLIST(&__stdio_files);
111 !(stdin = fdopen(STDIN_FILENO, NULL)) ||
112 !(stdout = fdopen(STDOUT_FILENO, NULL)) ||
113 !(stderr = fdopen(STDERR_FILENO, NULL))
116 SetIoErr(ERROR_NO_FREE_STORE);
117 return 0;
120 return 1;
123 ADD2INIT(__init_stdio, 5);