Rev 4874 | Rev 6536 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4874 | Rev 4921 | ||
---|---|---|---|
Line 30... | Line 30... | ||
30 | #include |
30 | #include |
31 | #ifdef __SCLE |
31 | #ifdef __SCLE |
32 | # include |
32 | # include |
33 | #endif |
33 | #endif |
Line -... | Line 34... | ||
- | 34 | ||
- | 35 | /* The following define determines if the per-reent stdin, stdout and stderr |
|
- | 36 | streams are closed during _reclaim_reent(). The stdin, stdout and stderr |
|
- | 37 | streams are initialized to use file descriptors 0, 1 and 2 respectively. In |
|
- | 38 | case _STDIO_CLOSE_PER_REENT_STD_STREAMS is defined these file descriptors |
|
- | 39 | will be closed via close() provided the owner of the reent structure |
|
- | 40 | triggerd the on demand reent initilization, see CHECK_INIT(). */ |
|
- | 41 | #ifndef __rtems__ |
|
- | 42 | #define _STDIO_CLOSE_PER_REENT_STD_STREAMS |
|
- | 43 | #endif |
|
- | 44 | ||
- | 45 | /* The following macros are supposed to replace calls to _flockfile/_funlockfile |
|
- | 46 | and __sfp_lock_acquire/__sfp_lock_release. In case of multi-threaded |
|
- | 47 | environments using pthreads, it's not sufficient to lock the stdio functions |
|
- | 48 | against concurrent threads accessing the same data, the locking must also be |
|
- | 49 | secured against thread cancellation. |
|
- | 50 | ||
- | 51 | The below macros have to be used in pairs. The _newlib_XXX_start macro |
|
- | 52 | starts with a opening curly brace, the _newlib_XXX_end macro ends with a |
|
- | 53 | closing curly brace, so the start macro and the end macro mark the code |
|
- | 54 | start and end of a critical section. In case the code leaves the critical |
|
- | 55 | section before reaching the end of the critical section's code end, use |
|
- | 56 | the appropriate _newlib_XXX_exit macro. */ |
|
- | 57 | ||
- | 58 | #if !defined (__SINGLE_THREAD__) && defined (_POSIX_THREADS) \ |
|
- | 59 | && !defined (__rtems__) |
|
- | 60 | #define _STDIO_WITH_THREAD_CANCELLATION_SUPPORT |
|
- | 61 | #endif |
|
- | 62 | ||
- | 63 | #ifdef _STDIO_WITH_THREAD_CANCELLATION_SUPPORT |
|
- | 64 | #include |
|
- | 65 | ||
- | 66 | /* Start a stream oriented critical section: */ |
|
- | 67 | # define _newlib_flockfile_start(_fp) \ |
|
- | 68 | { \ |
|
- | 69 | int __oldfpcancel; \ |
|
- | 70 | pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &__oldfpcancel); \ |
|
- | 71 | _flockfile (_fp) |
|
- | 72 | ||
- | 73 | /* Exit from a stream oriented critical section prematurely: */ |
|
- | 74 | # define _newlib_flockfile_exit(_fp) \ |
|
- | 75 | _funlockfile (_fp); \ |
|
- | 76 | pthread_setcancelstate (__oldfpcancel, &__oldfpcancel); |
|
- | 77 | ||
- | 78 | /* End a stream oriented critical section: */ |
|
- | 79 | # define _newlib_flockfile_end(_fp) \ |
|
- | 80 | _funlockfile (_fp); \ |
|
- | 81 | pthread_setcancelstate (__oldfpcancel, &__oldfpcancel); \ |
|
- | 82 | } |
|
- | 83 | ||
- | 84 | /* Start a stream list oriented critical section: */ |
|
- | 85 | # define _newlib_sfp_lock_start() \ |
|
- | 86 | { \ |
|
- | 87 | int __oldsfpcancel; \ |
|
- | 88 | pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &__oldsfpcancel); \ |
|
- | 89 | __sfp_lock_acquire () |
|
- | 90 | ||
- | 91 | /* Exit from a stream list oriented critical section prematurely: */ |
|
- | 92 | # define _newlib_sfp_lock_exit() \ |
|
- | 93 | __sfp_lock_release (); \ |
|
- | 94 | pthread_setcancelstate (__oldsfpcancel, &__oldsfpcancel); |
|
- | 95 | ||
- | 96 | /* End a stream list oriented critical section: */ |
|
- | 97 | # define _newlib_sfp_lock_end() \ |
|
- | 98 | __sfp_lock_release (); \ |
|
- | 99 | pthread_setcancelstate (__oldsfpcancel, &__oldsfpcancel); \ |
|
- | 100 | } |
|
- | 101 | ||
- | 102 | #else /* !_STDIO_WITH_THREAD_CANCELLATION_SUPPORT */ |
|
- | 103 | ||
- | 104 | # define _newlib_flockfile_start(_fp) \ |
|
- | 105 | { \ |
|
- | 106 | _flockfile(_fp) |
|
- | 107 | ||
- | 108 | # define _newlib_flockfile_exit(_fp) \ |
|
- | 109 | _funlockfile(_fp); \ |
|
- | 110 | ||
- | 111 | # define _newlib_flockfile_end(_fp) \ |
|
- | 112 | _funlockfile(_fp); \ |
|
- | 113 | } |
|
- | 114 | ||
- | 115 | # define _newlib_sfp_lock_start() \ |
|
- | 116 | { \ |
|
- | 117 | __sfp_lock_acquire () |
|
- | 118 | ||
- | 119 | # define _newlib_sfp_lock_exit() \ |
|
- | 120 | __sfp_lock_release (); |
|
- | 121 | ||
- | 122 | # define _newlib_sfp_lock_end() \ |
|
- | 123 | __sfp_lock_release (); \ |
|
- | 124 | } |
|
- | 125 | ||
Line 34... | Line 126... | ||
34 | 126 | #endif /* _STDIO_WITH_THREAD_CANCELLATION_SUPPORT */ |
|
35 | 127 | ||
36 | extern u_char *_EXFUN(__sccl, (char *, u_char *fmt)); |
128 | extern u_char *_EXFUN(__sccl, (char *, u_char *fmt)); |
37 | extern int _EXFUN(__svfscanf_r,(struct _reent *,FILE *, _CONST char *,va_list)); |
129 | extern int _EXFUN(__svfscanf_r,(struct _reent *,FILE *, _CONST char *,va_list)); |
Line 55... | Line 147... | ||
55 | extern FILE *_EXFUN(__sfp,(struct _reent *)); |
147 | extern FILE *_EXFUN(__sfp,(struct _reent *)); |
56 | extern int _EXFUN(__sflags,(struct _reent *,_CONST char*, int*)); |
148 | extern int _EXFUN(__sflags,(struct _reent *,_CONST char*, int*)); |
57 | extern int _EXFUN(__sflush_r,(struct _reent *,FILE *)); |
149 | extern int _EXFUN(__sflush_r,(struct _reent *,FILE *)); |
58 | extern int _EXFUN(__srefill_r,(struct _reent *,FILE *)); |
150 | extern int _EXFUN(__srefill_r,(struct _reent *,FILE *)); |
59 | extern _READ_WRITE_RETURN_TYPE _EXFUN(__sread,(struct _reent *, void *, char *, |
151 | extern _READ_WRITE_RETURN_TYPE _EXFUN(__sread,(struct _reent *, void *, char *, |
60 | int)); |
152 | _READ_WRITE_BUFSIZE_TYPE)); |
61 | extern _READ_WRITE_RETURN_TYPE _EXFUN(__seofread,(struct _reent *, void *, |
153 | extern _READ_WRITE_RETURN_TYPE _EXFUN(__seofread,(struct _reent *, void *, |
62 | char *, int)); |
154 | char *, |
- | 155 | _READ_WRITE_BUFSIZE_TYPE)); |
|
63 | extern _READ_WRITE_RETURN_TYPE _EXFUN(__swrite,(struct _reent *, void *, |
156 | extern _READ_WRITE_RETURN_TYPE _EXFUN(__swrite,(struct _reent *, void *, |
64 | const char *, int)); |
157 | const char *, |
- | 158 | _READ_WRITE_BUFSIZE_TYPE)); |
|
65 | extern _fpos_t _EXFUN(__sseek,(struct _reent *, void *, _fpos_t, int)); |
159 | extern _fpos_t _EXFUN(__sseek,(struct _reent *, void *, _fpos_t, int)); |
66 | extern int _EXFUN(__sclose,(struct _reent *, void *)); |
160 | extern int _EXFUN(__sclose,(struct _reent *, void *)); |
67 | extern int _EXFUN(__stextmode,(int)); |
161 | extern int _EXFUN(__stextmode,(int)); |
68 | extern _VOID _EXFUN(__sinit,(struct _reent *)); |
162 | extern _VOID _EXFUN(__sinit,(struct _reent *)); |
69 | extern _VOID _EXFUN(_cleanup_r,(struct _reent *)); |
163 | extern _VOID _EXFUN(_cleanup_r,(struct _reent *)); |
Line 74... | Line 168... | ||
74 | extern int _EXFUN(__submore, (struct _reent *, FILE *)); |
168 | extern int _EXFUN(__submore, (struct _reent *, FILE *)); |
Line 75... | Line 169... | ||
75 | 169 | ||
76 | #ifdef __LARGE64_FILES |
170 | #ifdef __LARGE64_FILES |
77 | extern _fpos64_t _EXFUN(__sseek64,(struct _reent *, void *, _fpos64_t, int)); |
171 | extern _fpos64_t _EXFUN(__sseek64,(struct _reent *, void *, _fpos64_t, int)); |
78 | extern _READ_WRITE_RETURN_TYPE _EXFUN(__swrite64,(struct _reent *, void *, |
172 | extern _READ_WRITE_RETURN_TYPE _EXFUN(__swrite64,(struct _reent *, void *, |
- | 173 | const char *, |
|
79 | const char *, int)); |
174 | _READ_WRITE_BUFSIZE_TYPE)); |
Line 80... | Line 175... | ||
80 | #endif |
175 | #endif |
Line 81... | Line 176... | ||
81 | 176 | ||
82 | /* Called by the main entry point fns to ensure stdio has been initialized. */ |
177 | /* Called by the main entry point fns to ensure stdio has been initialized. */ |
83 | 178 | ||
84 | #ifdef _REENT_SMALL |
179 | #ifdef _REENT_SMALL |
- | 180 | #define CHECK_INIT(ptr, fp) \ |
|
85 | #define CHECK_INIT(ptr, fp) \ |
181 | do \ |
86 | do \ |
182 | { \ |
87 | { \ |
183 | struct _reent *_check_init_ptr = (ptr); \ |
88 | if ((ptr) && !(ptr)->__sdidinit) \ |
184 | if ((_check_init_ptr) && !(_check_init_ptr)->__sdidinit) \ |
89 | __sinit (ptr); \ |
185 | __sinit (_check_init_ptr); \ |
90 | if ((fp) == (FILE *)&__sf_fake_stdin) \ |
186 | if ((fp) == (FILE *)&__sf_fake_stdin) \ |
91 | (fp) = _stdin_r(ptr); \ |
187 | (fp) = _stdin_r(_check_init_ptr); \ |
92 | else if ((fp) == (FILE *)&__sf_fake_stdout) \ |
188 | else if ((fp) == (FILE *)&__sf_fake_stdout) \ |
93 | (fp) = _stdout_r(ptr); \ |
189 | (fp) = _stdout_r(_check_init_ptr); \ |
94 | else if ((fp) == (FILE *)&__sf_fake_stderr) \ |
190 | else if ((fp) == (FILE *)&__sf_fake_stderr) \ |
95 | (fp) = _stderr_r(ptr); \ |
191 | (fp) = _stderr_r(_check_init_ptr); \ |
96 | } \ |
192 | } \ |
97 | while (0) |
193 | while (0) |
98 | #else /* !_REENT_SMALL */ |
194 | #else /* !_REENT_SMALL */ |
- | 195 | #define CHECK_INIT(ptr, fp) \ |
|
99 | #define CHECK_INIT(ptr, fp) \ |
196 | do \ |
100 | do \ |
197 | { \ |
101 | { \ |
198 | struct _reent *_check_init_ptr = (ptr); \ |
102 | if ((ptr) && !(ptr)->__sdidinit) \ |
199 | if ((_check_init_ptr) && !(_check_init_ptr)->__sdidinit) \ |
103 | __sinit (ptr); \ |
200 | __sinit (_check_init_ptr); \ |
Line 104... | Line 201... | ||
104 | } \ |
201 | } \ |
105 | while (0) |
202 | while (0) |
106 | #endif /* !_REENT_SMALL */ |
203 | #endif /* !_REENT_SMALL */ |
- | 204 | ||
107 | 205 | #define CHECK_STD_INIT(ptr) \ |
|
108 | #define CHECK_STD_INIT(ptr) \ |
206 | do \ |
109 | do \ |
207 | { \ |
110 | { \ |
208 | struct _reent *_check_init_ptr = (ptr); \ |
Line 111... | Line 209... | ||
111 | if ((ptr) && !(ptr)->__sdidinit) \ |
209 | if ((_check_init_ptr) && !(_check_init_ptr)->__sdidinit) \ |
112 | __sinit (ptr); \ |
210 | __sinit (_check_init_ptr); \ |
Line 134... | Line 232... | ||
134 | 232 | ||
135 | #define HASLB(fp) ((fp)->_lb._base != NULL) |
233 | #define HASLB(fp) ((fp)->_lb._base != NULL) |
136 | #define FREELB(ptr, fp) { _free_r(ptr,(char *)(fp)->_lb._base); \ |
234 | #define FREELB(ptr, fp) { _free_r(ptr,(char *)(fp)->_lb._base); \ |
Line -... | Line 235... | ||
- | 235 | (fp)->_lb._base = NULL; } |
|
137 | (fp)->_lb._base = NULL; } |
236 | |
138 | 237 | #ifdef _WIDE_ORIENT |
|
139 | /* |
238 | /* |
140 | * Set the orientation for a stream. If o > 0, the stream has wide- |
239 | * Set the orientation for a stream. If o > 0, the stream has wide- |
141 | * orientation. If o < 0, the stream has byte-orientation. |
240 | * orientation. If o < 0, the stream has byte-orientation. |
Line 151... | Line 250... | ||
151 | else \ |
250 | else \ |
152 | (fp)->_flags2 &= ~__SWID; \ |
251 | (fp)->_flags2 &= ~__SWID; \ |
153 | } \ |
252 | } \ |
154 | } \ |
253 | } \ |
155 | while (0) |
254 | while (0) |
- | 255 | #else |
|
- | 256 | #define ORIENT(fp,ori) |
|
- | 257 | #endif |
|
Line 156... | Line 258... | ||
156 | 258 | ||
Line 157... | Line 259... | ||
157 | /* WARNING: _dcvt is defined in the stdlib directory, not here! */ |
259 | /* WARNING: _dcvt is defined in the stdlib directory, not here! */ |
158 | 260 |