1 /*
2  * Copyright (c) 1990 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that the above copyright notice and this paragraph are
7  * duplicated in all such forms and that any documentation,
8  * advertising materials, and other materials related to such
9  * distribution and use acknowledge that the software was developed
10  * by the University of California, Berkeley.  The name of the
11  * University may not be used to endorse or promote products derived
12  * from this software without specific prior written permission.
13  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  *	%W% (UofMD/Berkeley) %G%
18  */
19 
20 /*
21  * Information local to this implementation of stdio,
22  * in particular, macros and private variables.
23  */
24 
25 #include <_ansi.h>
26 #include <stdarg.h>
27 #include <reent.h>
28 #include <unistd.h>
29 
30 extern int    _EXFUN(__svfscanf_r,(struct _reent *,FILE *, _CONST char *,va_list));
31 extern FILE  *_EXFUN(__sfp,(struct _reent *));
32 extern int    _EXFUN(__sflags,(struct _reent *,_CONST char*, int*));
33 extern int    _EXFUN(__srefill,(FILE *));
34 extern _READ_WRITE_RETURN_TYPE _EXFUN(__sread,(void *, char *, int));
35 extern _READ_WRITE_RETURN_TYPE _EXFUN(__swrite,(void *, char const *, int));
36 extern _fpos_t _EXFUN(__sseek,(void *, _fpos_t, int));
37 extern int    _EXFUN(__sclose,(void *));
38 extern int    _EXFUN(__stextmode,(int));
39 extern void   _EXFUN(__sinit,(struct _reent *));
40 extern void   _EXFUN(_cleanup_r,(struct _reent *));
41 extern void   _EXFUN(__smakebuf,(FILE *));
42 extern int    _EXFUN(_fwalk,(struct _reent *, int (*)(FILE *)));
43 struct _glue * _EXFUN(__sfmoreglue,(struct _reent *,int n));
44 extern int   _EXFUN(__srefill,(FILE *fp));
45 
46 /* Called by the main entry point fns to ensure stdio has been initialized.  */
47 
48 #define CHECK_INIT(fp) \
49   do					\
50     {					\
51       if (!_REENT->__sdidinit)		\
52 	__sinit (_REENT);		\
53     }					\
54   while (0)
55 
56 /* Return true iff the given FILE cannot be written now.  */
57 
58 #define	cantwrite(fp) \
59   ((((fp)->_flags & __SWR) == 0 || (fp)->_bf._base == NULL) && \
60    __swsetup(fp))
61 
62 /* Test whether the given stdio file has an active ungetc buffer;
63    release such a buffer, without restoring ordinary unread data.  */
64 
65 #define	HASUB(fp) ((fp)->_ub._base != NULL)
66 #define	FREEUB(fp) { \
67 	if ((fp)->_ub._base != (fp)->_ubuf) \
68 		_free_r(_REENT, (char *)(fp)->_ub._base); \
69 	(fp)->_ub._base = NULL; \
70 }
71 
72 /* Test for an fgetline() buffer.  */
73 
74 #define	HASLB(fp) ((fp)->_lb._base != NULL)
75 #define	FREELB(fp) { _free_r(_REENT,(char *)(fp)->_lb._base); (fp)->_lb._base = NULL; }
76 
77 /* WARNING: _dcvt is defined in the stdlib directory, not here!  */
78 
79 char *_EXFUN(_dcvt,(struct _reent *, char *, double, int, int, char, int));
80 char *_EXFUN(_sicvt,(char *, short, char));
81 char *_EXFUN(_icvt,(char *, int, char));
82 char *_EXFUN(_licvt,(char *, long, char));
83 #ifdef __GNUC__
84 char *_EXFUN(_llicvt,(char *, long long, char));
85 #endif
86 
87 #define CVT_BUF_SIZE 128
88 
89 #define	NDYNAMIC 4	/* add four more whenever necessary */
90