source: svn/newcon3bcm2_21bu/toolchain/mips-linux-uclibc/include/bits/uClibc_stdio.h @ 43

Last change on this file since 43 was 43, checked in by megakiss, 11 years ago

광주방송 OTC 주파수 369Mhz로 변경

  • Property svn:executable set to *
File size: 15.7 KB
Line 
1/* Copyright (C) 2002-2004   Manuel Novoa III    <mjn3@codepoet.org>
2 *
3 * GNU Library General Public License (LGPL) version 2 or later.
4 *
5 * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
6 */
7
8#ifndef _STDIO_H
9#error Always include <stdio.h> rather than <bits/uClibc_stdio.h>
10#endif
11
12/**********************************************************************/
13
14#define __STDIO_BUFFERS
15/* ANSI/ISO mandate at least 256. */
16#if defined(__UCLIBC_HAS_STDIO_BUFSIZ_NONE__)
17/* Fake this because some apps use stdio.h BUFSIZ. */
18#define __STDIO_BUFSIZ                  256
19#undef __STDIO_BUFFERS
20#elif defined(__UCLIBC_HAS_STDIO_BUFSIZ_256__)
21#define __STDIO_BUFSIZ                  256
22#elif defined(__UCLIBC_HAS_STDIO_BUFSIZ_512__)
23#define __STDIO_BUFSIZ                  512
24#elif defined(__UCLIBC_HAS_STDIO_BUFSIZ_1024__)
25#define __STDIO_BUFSIZ             1024
26#elif defined(__UCLIBC_HAS_STDIO_BUFSIZ_2048__)
27#define __STDIO_BUFSIZ             2048
28#elif defined(__UCLIBC_HAS_STDIO_BUFSIZ_4096__)
29#define __STDIO_BUFSIZ             4096
30#elif defined(__UCLIBC_HAS_STDIO_BUFSIZ_8192__)
31#define __STDIO_BUFSIZ             8192
32#else
33#error config seems to be out of sync regarding bufsiz options
34#endif
35
36#ifdef __UCLIBC_HAS_STDIO_BUFSIZ_NONE__
37#define __STDIO_BUILTIN_BUF_SIZE                0
38#else  /* __UCLIBC_HAS_STDIO_BUFSIZ_NONE__ */
39#if defined(__UCLIBC_HAS_STDIO_BUILTIN_BUFFER_NONE__)
40#define __STDIO_BUILTIN_BUF_SIZE                0
41#elif defined(__UCLIBC_HAS_STDIO_BUILTIN_BUFFER_4__)
42#define __STDIO_BUILTIN_BUF_SIZE                4
43#elif defined(__UCLIBC_HAS_STDIO_BUILTIN_BUFFER_8__)
44#define __STDIO_BUILTIN_BUF_SIZE                8
45#else
46#error config seems to be out of sync regarding builtin buffer size
47#endif
48#endif
49
50#if defined(__STDIO_BUFFERS) || defined(__UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__) || defined(__UCLIBC_HAS_THREADS__)
51#define __STDIO_HAS_OPENLIST 1
52#else
53#undef __STDIO_HAS_OPENLIST
54#endif
55
56/**********************************************************************/
57/* Make sure defines related to large files are consistent. */
58#ifdef _LIBC
59
60#ifdef __UCLIBC_HAS_LFS__
61#undef __USE_LARGEFILE
62#undef __USE_LARGEFILE64
63#undef __USE_FILE_OFFSET64
64/* If we're actually building uClibc with large file support, only define... */
65#define __USE_LARGEFILE64       1
66#endif /* __UCLIBC_HAS_LFS__ */
67
68#else  /* not _LIBC */
69
70#ifndef __UCLIBC_HAS_LFS__
71#if defined(__LARGEFILE64_SOURCE) || defined(__USE_LARGEFILE64) || defined(__USE_FILE_OFFSET64)
72#error Sorry... uClibc was built without large file support!
73#endif
74#endif /* __UCLIBC_HAS_LFS__ */
75
76#endif /* _LIBC */
77/**********************************************************************/
78#ifdef __UCLIBC_HAS_WCHAR__
79
80#define __need_wchar_t
81#include <stddef.h>
82
83/* Note: we don't really need mbstate for 8-bit locales.  We do for UTF-8.
84 * For now, always use it. */
85#define __STDIO_MBSTATE
86#define __need_mbstate_t
87#include <wchar.h>
88
89#endif
90/**********************************************************************/
91/* Currently unimplemented/untested */
92/* #define __STDIO_FLEXIBLE_SETVBUF */
93
94#ifdef __UCLIBC_HAS_STDIO_GETC_MACRO__
95#define __STDIO_GETC_MACRO
96#endif
97
98#ifdef __UCLIBC_HAS_STDIO_PUTC_MACRO__
99#define __STDIO_PUTC_MACRO
100#endif
101
102
103/* These are consistency checks on the different options */
104
105#ifndef __STDIO_BUFFERS
106#undef __STDIO_GETC_MACRO
107#undef __STDIO_PUTC_MACRO
108#endif
109
110#ifdef __BCC__
111#undef __UCLIBC_HAS_LFS__
112#endif
113
114#ifndef __UCLIBC_HAS_LFS__
115#undef __UCLIBC_HAS_FOPEN_LARGEFILE_MODE__
116#endif
117
118/**********************************************************************/
119#ifdef __UCLIBC_HAS_THREADS__
120/* Need this for pthread_mutex_t. */
121#include <bits/pthreadtypes.h>
122
123/* user_locking
124 * 0 : do auto locking/unlocking
125 * 1 : user does locking/unlocking
126 * 2 : initial state prior to thread initialization
127 *     with no auto locking/unlocking
128 *
129 * When threading is initialized, walk the stdio open stream list
130 * and do  "if (user_locking == 2) user_locking = 0;".
131 *
132 * This way, we avoid calling the weak lock/unlock functions.
133 */
134
135#define __STDIO_AUTO_THREADLOCK_VAR                     int __infunc_user_locking
136
137#define __STDIO_AUTO_THREADLOCK(__stream)                                                               \
138        if ((__infunc_user_locking = (__stream)->__user_locking) == 0) {        \
139                __pthread_mutex_lock(&(__stream)->__lock);                                              \
140        }
141
142#define __STDIO_AUTO_THREADUNLOCK(__stream)                             \
143        if (__infunc_user_locking == 0) {                                       \
144                __pthread_mutex_unlock(&(__stream)->__lock);            \
145        }
146
147#define __STDIO_SET_USER_LOCKING(__stream)      ((__stream)->__user_locking = 1)
148
149#define __STDIO_ALWAYS_THREADLOCK(__stream)     \
150                __pthread_mutex_lock(&(__stream)->__lock)
151
152#define __STDIO_ALWAYS_THREADTRYLOCK(__stream)  \
153                __pthread_mutex_trylock(&(__stream)->__lock)
154
155#define __STDIO_ALWAYS_THREADUNLOCK(__stream) \
156                __pthread_mutex_unlock(&(__stream)->__lock)
157
158#else  /* __UCLIBC_HAS_THREADS__ */
159
160#define __STDIO_AUTO_THREADLOCK_VAR                             ((void)0)
161
162#define __STDIO_AUTO_THREADLOCK(__stream)               ((void)0)
163#define __STDIO_AUTO_THREADUNLOCK(__stream)             ((void)0)
164
165#define __STDIO_SET_USER_LOCKING(__stream)              ((void)0)
166
167#define __STDIO_ALWAYS_THREADLOCK(__stream)             ((void)0)
168#define __STDIO_ALWAYS_THREADTRYLOCK(__stream)  (0)     /* Always succeed. */
169#define __STDIO_ALWAYS_THREADUNLOCK(__stream)   ((void)0)
170
171#endif /* __UCLIBC_HAS_THREADS__ */
172/**********************************************************************/
173
174#define __STDIO_IOFBF 0         /* Fully buffered.  */
175#define __STDIO_IOLBF 1         /* Line buffered.  */
176#define __STDIO_IONBF 2         /* No buffering.  */
177
178typedef struct {
179        __off_t __pos;
180#ifdef __STDIO_MBSTATE
181        __mbstate_t __mbstate;
182#endif
183#ifdef __UCLIBC_HAS_WCHAR__
184        int __mblen_pending;
185#endif
186} __STDIO_fpos_t;
187
188#ifdef __UCLIBC_HAS_LFS__
189typedef struct {
190        __off64_t __pos;
191#ifdef __STDIO_MBSTATE
192        __mbstate_t __mbstate;
193#endif
194#ifdef __UCLIBC_HAS_WCHAR__
195        int __mblen_pending;
196#endif
197} __STDIO_fpos64_t;
198#endif
199
200/**********************************************************************/
201#ifdef __UCLIBC_HAS_LFS__
202typedef __off64_t __offmax_t;   /* TODO -- rename this? */
203#else
204typedef __off_t __offmax_t;             /* TODO -- rename this? */
205#endif
206
207/**********************************************************************/
208#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
209
210typedef __ssize_t __io_read_fn(void *__cookie, char *__buf, size_t __bufsize);
211typedef __ssize_t __io_write_fn(void *__cookie,
212                                                                __const char *__buf, size_t __bufsize);
213/* NOTE: GLIBC difference!!! -- fopencookie seek function
214 * For glibc, the type of pos is always (__off64_t *) but in our case
215 * it is type (__off_t *) when the lib is built without large file support.
216 */
217typedef int __io_seek_fn(void *__cookie, __offmax_t *__pos, int __whence);
218typedef int __io_close_fn(void *__cookie);
219
220typedef struct {
221        __io_read_fn  *read;
222        __io_write_fn *write;
223        __io_seek_fn  *seek;
224        __io_close_fn *close;
225} _IO_cookie_io_functions_t;
226
227#if defined(_LIBC) || defined(_GNU_SOURCE)
228
229typedef __io_read_fn cookie_read_function_t;
230typedef __io_write_fn cookie_write_function_t;
231typedef __io_seek_fn cookie_seek_function_t;
232typedef __io_close_fn cookie_close_function_t;
233
234typedef _IO_cookie_io_functions_t cookie_io_functions_t;
235
236#endif
237
238#endif
239/**********************************************************************/
240
241struct __STDIO_FILE_STRUCT {
242        unsigned short __modeflags;
243        /* There could be a hole here, but modeflags is used most.*/
244#ifdef __UCLIBC_HAS_WCHAR__
245        unsigned char __ungot_width[2]; /* 0: current (building) char; 1: scanf */
246        /* Move the following futher down to avoid problems with getc/putc
247         * macros breaking shared apps when wchar config support is changed. */
248        /* wchar_t ungot[2]; */
249#else  /* __UCLIBC_HAS_WCHAR__ */
250        unsigned char __ungot[2];
251#endif /* __UCLIBC_HAS_WCHAR__ */
252        int __filedes;
253#ifdef __STDIO_BUFFERS
254        unsigned char *__bufstart;      /* pointer to buffer */
255        unsigned char *__bufend;        /* pointer to 1 past end of buffer */
256        unsigned char *__bufpos;
257        unsigned char *__bufread; /* pointer to 1 past last buffered read char */
258
259#ifdef __STDIO_GETC_MACRO
260        unsigned char *__bufgetc_u;     /* 1 past last readable by getc_unlocked */
261#endif /* __STDIO_GETC_MACRO */
262#ifdef __STDIO_PUTC_MACRO
263        unsigned char *__bufputc_u;     /* 1 past last writeable by putc_unlocked */
264#endif /* __STDIO_PUTC_MACRO */
265
266#endif /* __STDIO_BUFFERS */
267
268#ifdef __STDIO_HAS_OPENLIST
269        struct __STDIO_FILE_STRUCT *__nextopen;
270#endif
271#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
272        void *__cookie;
273        _IO_cookie_io_functions_t __gcs;
274#endif
275#ifdef __UCLIBC_HAS_WCHAR__
276        wchar_t __ungot[2];
277#endif
278#ifdef __STDIO_MBSTATE
279        __mbstate_t __state;
280#endif
281#ifdef __UCLIBC_HAS_XLOCALE__
282        void *__unused;                         /* Placeholder for codeset binding. */
283#endif
284#ifdef __UCLIBC_HAS_THREADS__
285        int __user_locking;
286        pthread_mutex_t __lock;
287#endif
288/* Everything after this is unimplemented... and may be trashed. */
289#if __STDIO_BUILTIN_BUF_SIZE > 0
290        unsigned char __builtinbuf[__STDIO_BUILTIN_BUF_SIZE];
291#endif /* __STDIO_BUILTIN_BUF_SIZE > 0 */
292};
293
294
295/***********************************************************************/
296/* Having ungotten characters implies the stream is reading.
297 * The scheme used here treats the least significant 2 bits of
298 * the stream's modeflags member as follows:
299 *   0 0   Not currently reading.
300 *   0 1   Reading, but no ungetc() or scanf() push back chars.
301 *   1 0   Reading with one ungetc() char (ungot[1] is 1)
302 *         or one scanf() pushed back char (ungot[1] is 0).
303 *   1 1   Reading with both an ungetc() char and a scanf()
304 *         pushed back char.  Note that this must be the result
305 *         of a scanf() push back (in ungot[0]) _followed_ by
306 *         an ungetc() call (in ungot[1]).
307 *
308 * Notes:
309 *   scanf() can NOT use ungetc() to push back characters.
310 *     (See section 7.19.6.2 of the C9X rationale -- WG14/N897.)
311 */
312
313#define __MASK_READING          0x0003U /* (0x0001 | 0x0002) */
314#define __FLAG_READING          0x0001U
315#define __FLAG_UNGOT            0x0002U
316#define __FLAG_EOF                      0x0004U
317#define __FLAG_ERROR            0x0008U
318#define __FLAG_WRITEONLY        0x0010U
319#define __FLAG_READONLY         0x0020U /* (__FLAG_WRITEONLY << 1) */
320#define __FLAG_WRITING          0x0040U
321#define __FLAG_NARROW       0x0080U
322
323#define __FLAG_FBF          0x0000U /* must be 0 */
324#define __FLAG_LBF          0x0100U
325#define __FLAG_NBF          0x0200U /* (__FLAG_LBF << 1) */
326#define __MASK_BUFMODE      0x0300U /* (__FLAG_LBF|__FLAG_NBF) */
327#define __FLAG_APPEND       0x0400U /* fixed! == O_APPEND for linux */
328#define __FLAG_WIDE                     0x0800U
329/* available slot           0x1000U */
330#define __FLAG_FREEFILE         0x2000U
331#define __FLAG_FREEBUF          0x4000U
332#define __FLAG_LARGEFILE    0x8000U /* fixed! == 0_LARGEFILE for linux */
333
334/* Note: In no-buffer mode, it would be possible to pack the necessary
335 * flags into one byte.  Since we wouldn't be buffering and there would
336 * be no support for wchar, the only flags we would need would be:
337 *   2 bits : ungot count
338 *   2 bits : eof + error
339 *   2 bits : readonly + writeonly
340 *   1 bit  : freefile
341 *   1 bit  : appending
342 * So, for a very small system (< 128 files) we might have a
343 * 4-byte FILE struct of:
344 *   unsigned char flags;
345 *   signed char filedes;
346 *   unsigned char ungot[2];
347 */
348/**********************************************************************
349 * PROTOTYPES OF INTERNAL FUNCTIONS
350 **********************************************************************/
351#ifdef _LIBC
352
353extern void _stdio_init(void);
354extern void _stdio_term(void);
355
356#ifdef __STDIO_HAS_OPENLIST
357
358extern struct __STDIO_FILE_STRUCT *_stdio_openlist;
359
360#ifdef __UCLIBC_HAS_THREADS__
361extern pthread_mutex_t _stdio_openlist_lock;
362extern int _stdio_openlist_delflag;
363extern int _stdio_user_locking;
364extern void __stdio_init_mutex(pthread_mutex_t *m);
365#endif
366
367#endif
368
369#endif
370/**********************************************************************/
371
372#define __CLEARERR_UNLOCKED(__stream) \
373        ((void)((__stream)->__modeflags &= ~(__FLAG_EOF|__FLAG_ERROR)))
374#define __FEOF_UNLOCKED(__stream)       ((__stream)->__modeflags & __FLAG_EOF)
375#define __FERROR_UNLOCKED(__stream)     ((__stream)->__modeflags & __FLAG_ERROR)
376
377#ifdef __UCLIBC_HAS_THREADS__
378# define __CLEARERR(__stream)   (clearerr)(__stream)
379# define __FERROR(__stream)             (ferror)(__stream)
380# define __FEOF(__stream)               (feof)(__stream)
381#else
382# define __CLEARERR(__stream)   __CLEARERR_UNLOCKED(__stream)
383# define __FERROR(__stream)             __FERROR_UNLOCKED(__stream)
384# define __FEOF(__stream)               __FEOF_UNLOCKED(__stream)
385#endif
386
387extern int __fgetc_unlocked(FILE *__stream);
388extern int __fputc_unlocked(int __c, FILE *__stream);
389
390/* First define the default definitions.  They overriden below as necessary. */
391#define __FGETC_UNLOCKED(__stream)              (__fgetc_unlocked)((__stream))
392#define __FGETC(__stream)                               (fgetc)((__stream))
393#define __GETC_UNLOCKED_MACRO(__stream) (__fgetc_unlocked)((__stream))
394#define __GETC_UNLOCKED(__stream)               (__fgetc_unlocked)((__stream))
395#define __GETC(__stream)                                (fgetc)((__stream))
396
397#define __FPUTC_UNLOCKED(__c, __stream) (__fputc_unlocked)((__c),(__stream))
398#define __FPUTC(__c, __stream)                  (fputc)((__c),(__stream))
399#define __PUTC_UNLOCKED_MACRO(__c, __stream) (__fputc_unlocked)((__c),(__stream))
400#define __PUTC_UNLOCKED(__c, __stream)  (__fputc_unlocked)((__c),(__stream))
401#define __PUTC(__c, __stream)                   (fputc)((__c),(__stream))
402
403
404#ifdef __STDIO_GETC_MACRO
405
406extern FILE *__stdin;                   /* For getchar() macro. */
407
408# undef  __GETC_UNLOCKED_MACRO
409# define __GETC_UNLOCKED_MACRO(__stream)                                        \
410                ( ((__stream)->__bufpos < (__stream)->__bufgetc_u)      \
411                  ? (*(__stream)->__bufpos++)                                           \
412                  : __fgetc_unlocked(__stream) )
413
414# if 0
415        /* Classic macro approach.  getc{_unlocked} can have side effects. */
416#  undef  __GETC_UNLOCKED
417#  define __GETC_UNLOCKED(__stream)             __GETC_UNLOCKED_MACRO((__stream))
418#  ifndef __UCLIBC_HAS_THREADS__
419#   undef  __GETC
420#   define __GETC(__stream)                             __GETC_UNLOCKED_MACRO((__stream))
421#  endif
422
423# else
424        /* Using gcc extension for safety and additional inlining. */
425#  undef  __FGETC_UNLOCKED
426#  define __FGETC_UNLOCKED(__stream)            \
427                (__extension__ ({                                       \
428                        FILE *__S = (__stream);                 \
429                        __GETC_UNLOCKED_MACRO(__S);             \
430                }) )
431
432#  undef  __GETC_UNLOCKED
433#  define __GETC_UNLOCKED(__stream)             __FGETC_UNLOCKED((__stream))
434
435#  ifdef __UCLIBC_HAS_THREADS__
436#   undef  __FGETC
437#   define __FGETC(__stream)                            \
438                (__extension__ ({                                       \
439                        FILE *__S = (__stream);                 \
440                        ((__S->__user_locking )                 \
441                         ? __GETC_UNLOCKED_MACRO(__S)   \
442                         : (fgetc)(__S));                               \
443                }) )
444
445#   undef  __GETC
446#   define __GETC(__stream)                             __FGETC((__stream))
447
448#  else
449
450#   undef  __FGETC
451#   define __FGETC(__stream)                    __FGETC_UNLOCKED((__stream))
452#   undef  __GETC
453#   define __GETC(__stream)                             __FGETC_UNLOCKED((__stream))
454
455#  endif
456# endif
457
458#else
459
460#endif /* __STDIO_GETC_MACRO */
461
462
463#ifdef __STDIO_PUTC_MACRO
464
465extern FILE *__stdout;                  /* For putchar() macro. */
466
467# undef  __PUTC_UNLOCKED_MACRO
468# define __PUTC_UNLOCKED_MACRO(__c, __stream)                                           \
469                ( ((__stream)->__bufpos < (__stream)->__bufputc_u)      \
470                  ? (*(__stream)->__bufpos++) = (__c)                           \
471                  : __fputc_unlocked((__c),(__stream)) )
472
473# if 0
474        /* Classic macro approach.  putc{_unlocked} can have side effects.*/
475#  undef  __PUTC_UNLOCKED
476#  define __PUTC_UNLOCKED(__c, __stream) \
477                                                                        __PUTC_UNLOCKED_MACRO((__c), (__stream))
478#  ifndef __UCLIBC_HAS_THREADS__
479#   undef  __PUTC
480#   define __PUTC(__c, __stream)        __PUTC_UNLOCKED_MACRO((__c), (__stream))
481#  endif
482
483# else
484        /* Using gcc extension for safety and additional inlining. */
485
486#  undef  __FPUTC_UNLOCKED
487#  define __FPUTC_UNLOCKED(__c, __stream)               \
488                (__extension__ ({                                               \
489                        FILE *__S = (__stream);                         \
490                        __PUTC_UNLOCKED_MACRO((__c),__S);       \
491                }) )
492
493#  undef  __PUTC_UNLOCKED
494#  define __PUTC_UNLOCKED(__c, __stream)        __FPUTC_UNLOCKED((__c), (__stream))
495
496#  ifdef __UCLIBC_HAS_THREADS__
497#   undef  __FPUTC
498#   define __FPUTC(__c, __stream)                               \
499                (__extension__ ({                                               \
500                        FILE *__S = (__stream);                         \
501                        ((__S->__user_locking)                          \
502                         ? __PUTC_UNLOCKED_MACRO((__c),__S)     \
503                         : (fputc)((__c),__S));                         \
504                }) )
505
506#   undef  __PUTC
507#   define __PUTC(__c, __stream)                __FPUTC((__c), (__stream))
508
509#  else
510
511#   undef  __FPUTC
512#   define __FPUTC(__c, __stream)               __FPUTC_UNLOCKED((__c),(__stream))
513#   undef  __PUTC
514#   define __PUTC(__c, __stream)                __FPUTC_UNLOCKED((__c),(__stream))
515
516#  endif
517# endif
518
519#endif /* __STDIO_PUTC_MACRO */
Note: See TracBrowser for help on using the repository browser.