]>
Commit | Line | Data |
---|---|---|
478b92f0 | 1 | /* Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc. |
28f540f4 RM |
2 | Ported to standalone by Joel Sherrill jsherril@redstone-emh2.army.mil, |
3 | On-Line Applications Research Corporation. | |
478b92f0 | 4 | This file is part of the GNU C Library. |
c4029823 | 5 | |
478b92f0 | 6 | The GNU C Library is free software; you can redistribute it and/or |
41bdb6e2 AJ |
7 | modify it under the terms of the GNU Lesser General Public |
8 | License as published by the Free Software Foundation; either | |
9 | version 2.1 of the License, or (at your option) any later version. | |
28f540f4 | 10 | |
478b92f0 UD |
11 | The GNU C Library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
41bdb6e2 | 14 | Lesser General Public License for more details. |
28f540f4 | 15 | |
41bdb6e2 AJ |
16 | You should have received a copy of the GNU Lesser General Public |
17 | License along with the GNU C Library; if not, write to the Free | |
18 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | |
19 | 02111-1307 USA. */ | |
28f540f4 | 20 | |
28f540f4 RM |
21 | #include <errno.h> |
22 | #include <fcntl.h> | |
23 | #include <stdarg.h> | |
24 | #include <stddef.h> | |
25 | ||
26 | #include <stdio.h> | |
5107cf1d | 27 | #include <bits/stdio_lim.h> |
28f540f4 RM |
28 | #include <unistd.h> |
29 | ||
30 | #define __DECLARE_FILE_DESCRIPTORS__ | |
31 | ||
32 | #include "filedesc.h" | |
33 | ||
34 | /* Open FILE with access OFLAG. If OFLAG includes O_CREAT, | |
35 | a third argument is the file protection. */ | |
36 | int | |
c4029823 UD |
37 | __open (file, oflag) |
38 | const char *file; | |
39 | int oflag; | |
28f540f4 RM |
40 | { |
41 | int mode; | |
42 | int newfd; | |
43 | int index; | |
44 | ||
45 | if (file == NULL) | |
46 | { | |
c4029823 | 47 | __set_errno (EINVAL); |
28f540f4 RM |
48 | return -1; |
49 | } | |
50 | ||
51 | if (oflag & O_CREAT) | |
52 | { | |
53 | va_list arg; | |
54 | va_start(arg, oflag); | |
55 | mode = va_arg(arg, int); | |
56 | va_end(arg); | |
57 | } | |
58 | ||
59 | /* | |
60 | * Find an open slot. | |
61 | */ | |
62 | ||
63 | newfd = -1; | |
64 | ||
65 | for ( index=0 ; index< FOPEN_MAX ; index++ ) | |
66 | if ( !__FD_Table[ index ].in_use ) { | |
67 | newfd = index; | |
68 | break; | |
69 | } | |
70 | ||
71 | if ( newfd == -1 ) { | |
c4029823 | 72 | __set_errno (ENFILE); |
28f540f4 RM |
73 | return -1; |
74 | } | |
75 | ||
c4029823 | 76 | /* |
28f540f4 RM |
77 | * Initialize the open slot |
78 | */ | |
79 | ||
80 | __FD_Table[ newfd ].in_use = 1; | |
81 | __FD_Table[ newfd ].flags = oflag; | |
c4029823 | 82 | |
28f540f4 RM |
83 | return newfd; |
84 | } | |
85 | ||
86 | /* Initialization Code for Console I/O */ | |
87 | ||
88 | #ifdef HAVE_GNU_LD | |
89 | static | |
90 | #endif | |
91 | void | |
c4029823 UD |
92 | __NONE_init_console_io (argc, argv, envp) |
93 | int argc; | |
94 | char **argv; | |
95 | char **envp; | |
28f540f4 RM |
96 | { |
97 | int index; | |
98 | ||
99 | for ( index=0 ; index< FOPEN_MAX ; index++ ) | |
100 | __FD_Table[ index ].in_use = 0; | |
101 | ||
102 | stdin = fopen( "", "r" ); | |
103 | ||
104 | stdout = fopen( "", "w" ); | |
105 | ||
106 | stderr = fopen( "", "w" ); | |
107 | ||
108 | /* | |
109 | * Line buffer the standard input and output and use no buffering for | |
110 | * standard error. | |
111 | */ | |
112 | ||
113 | setvbuf( stdin, NULL, _IOLBF, BUFSIZ ); | |
114 | setvbuf( stdout, NULL, _IOLBF, BUFSIZ ); | |
115 | setvbuf( stderr, NULL, _IONBF, BUFSIZ ); | |
116 | ||
117 | (void) &__NONE_init_console_io; /* Avoid "defined but not used" warning. */ | |
118 | } | |
119 | ||
120 | #ifdef HAVE_GNU_LD | |
121 | text_set_element (__libc_subinit, __NONE_init_console_io); | |
122 | #endif | |
123 | ||
124 | weak_alias (__open, open) |