1 /*
2 ANSI C Runtime Library
3
4 Copyright 1983-2004 Green Hills Software, Inc.
5
6 This program is the property of Green Hills Software, Inc,
7 its contents are proprietary information and no part of it
8 is to be disclosed to anyone except employees of Green Hills
9 Software, Inc., or as agreed in writing signed by the President
10 of Green Hills Software, Inc.
11 */
12
13 #include "indos.h"
14 #include <stdio.h>
15
16 /*
17 This file is included in every library module which uses FOPEN_MAX
18 The value of FOPEN_MAX which is used to compile the library becomes
19 a maximum limit at runtime. On the other hand, the value of FOPEN_MAX
20 in stdio.h is a minimum which MUST be supported on every system, unless
21 we want to have different versions of stdio.h. Some systems still
22 allow only 20, but many systems allow 40, 60, 100 or more. We would
23 change stdio.h to a higher limit, but Plum Hall insists that FOPEN_MAX
24 files can be opened, so for the sake of the worst-case systems, that
25 value remains 20, even though the library is compiled with a much
26 higher limit and will allow the higher limit if the OS handles it.
27 */
28
29 #include "inddef.h"
30 #include "ind_thrd.h"
31
32 #ifndef FOPEN_MAX
33 #define FOPEN_MAX 100
34 #elif (FOPEN_MAX < 100) && !defined(MINIMUM_SPACE) && !defined(__INTEGRITY_SHARED_LIBS)
35 #undef FOPEN_MAX
36 #define FOPEN_MAX 100
37 #endif
38
39 unsigned short __gh_FOPEN_MAX = FOPEN_MAX;
40 #pragma weak __gh_FOPEN_MAX
41
42 struct _iobuf _iob[FOPEN_MAX];
43 void *_iob_lock[FOPEN_MAX+1];
44
45 #pragma weak _iob
46 #pragma weak _iob_lock
47
48 /* If __ghs_flock_ptr always returns a valid pointer, we can reduce the
49 amount of code in flockfile which is executed for every file and
50 in some cases for every char. */
__ghs_flock_ptr(void * stream)51 void ** __ghs_flock_ptr(void * stream)
52 {
53 unsigned int index = ((FILE *)stream) - _iob;
54 if (index > __gh_FOPEN_MAX)
55 index = __gh_FOPEN_MAX;
56 return &_iob_lock[index];
57 }
58
__ghs_flock_word(void * stream)59 void * __ghs_flock_word(void * stream)
60 {
61 return *__ghs_flock_ptr(stream);
62 }
63
64
__gh_iob_init(void)65 void __gh_iob_init(void)
66 {
67 #ifndef LESS_BUFFERED_IO
68 #ifdef UN_BUFFERED_STD
69 _iob[0]._io_buffering = _IONBF;
70 _iob[1]._io_buffering = _IONBF;
71 #else
72 _iob[0]._io_buffering = _IOLBF;
73 _iob[1]._io_buffering = _IOLBF;
74 #endif
75 _iob[2]._io_buffering = _IONBF;
76 #endif /* LESS_BUFFERED_IO */
77 _iob[0]._io_readable = 1;
78 _iob[1]._io_writable = 1;
79 _iob[2]._io_writable = 1;
80 _iob[1]._io_channel = 1;
81 _iob[2]._io_channel = 2;
82 /* locks are allocated per address space for stdin/out/err at startup
83 * and never released */
84 LOCKCREATE(&_iob[0]);
85 LOCKCREATE(&_iob[1]);
86 LOCKCREATE(&_iob[2]);
87 }
88