The Pedigree Project  0.1
local.h
1 /*
2  * Copyright (c) 1990, 2007 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 <reent.h>
27 #include <stdarg.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <unistd.h>
31 #ifdef __SCLE
32 #include <io.h>
33 #endif
34 
35 extern u_char *_EXFUN(__sccl, (char *, u_char *fmt));
36 extern int
37  _EXFUN(__svfscanf_r, (struct _reent *, FILE *, _CONST char *, va_list));
38 extern int
39  _EXFUN(__ssvfscanf_r, (struct _reent *, FILE *, _CONST char *, va_list));
40 extern int
41  _EXFUN(__svfiscanf_r, (struct _reent *, FILE *, _CONST char *, va_list));
42 extern int
43  _EXFUN(__ssvfiscanf_r, (struct _reent *, FILE *, _CONST char *, va_list));
44 int _EXFUN(
45  _svfprintf_r, (struct _reent *, FILE *, const char *,
46  va_list) _ATTRIBUTE((__format__(__printf__, 3, 0))));
47 int _EXFUN(
48  _svfiprintf_r, (struct _reent *, FILE *, const char *,
49  va_list) _ATTRIBUTE((__format__(__printf__, 3, 0))));
50 extern FILE *_EXFUN(__sfp, (struct _reent *) );
51 extern int _EXFUN(__sflags, (struct _reent *, _CONST char *, int *) );
52 extern int _EXFUN(__srefill_r, (struct _reent *, FILE *) );
53 extern _READ_WRITE_RETURN_TYPE
54  _EXFUN(__sread, (struct _reent *, void *, char *, int) );
55 extern _READ_WRITE_RETURN_TYPE
56  _EXFUN(__swrite, (struct _reent *, void *, const char *, int) );
57 extern _fpos_t _EXFUN(__sseek, (struct _reent *, void *, _fpos_t, int) );
58 extern int _EXFUN(__sclose, (struct _reent *, void *) );
59 extern int _EXFUN(__stextmode, (int) );
60 extern _VOID _EXFUN(__sinit, (struct _reent *) );
61 extern _VOID _EXFUN(_cleanup_r, (struct _reent *) );
62 extern _VOID _EXFUN(__smakebuf_r, (struct _reent *, FILE *) );
63 extern int _EXFUN(_fwalk, (struct _reent *, int (*)(FILE *)));
64 extern int
65  _EXFUN(_fwalk_reent, (struct _reent *, int (*)(struct _reent *, FILE *)));
66 struct _glue *_EXFUN(__sfmoreglue, (struct _reent *, int n));
67 extern int _EXFUN(__submore, (struct _reent *, FILE *) );
68 
69 #ifdef __LARGE64_FILES
70 extern _fpos64_t _EXFUN(__sseek64, (struct _reent *, void *, _fpos64_t, int) );
71 extern _READ_WRITE_RETURN_TYPE
72  _EXFUN(__swrite64, (struct _reent *, void *, const char *, int) );
73 #endif
74 
75 /* Called by the main entry point fns to ensure stdio has been initialized. */
76 
77 #ifdef _REENT_SMALL
78 #define CHECK_INIT(ptr, fp) \
79  do \
80  { \
81  if ((ptr) && !(ptr)->__sdidinit) \
82  __sinit(ptr); \
83  if ((fp) == (FILE *) &__sf_fake_stdin) \
84  (fp) = _stdin_r(ptr); \
85  else if ((fp) == (FILE *) &__sf_fake_stdout) \
86  (fp) = _stdout_r(ptr); \
87  else if ((fp) == (FILE *) &__sf_fake_stderr) \
88  (fp) = _stderr_r(ptr); \
89  } while (0)
90 #else /* !_REENT_SMALL */
91 #define CHECK_INIT(ptr, fp) \
92  do \
93  { \
94  if ((ptr) && !(ptr)->__sdidinit) \
95  __sinit(ptr); \
96  } while (0)
97 #endif /* !_REENT_SMALL */
98 
99 #define CHECK_STD_INIT(ptr) \
100  do \
101  { \
102  if ((ptr) && !(ptr)->__sdidinit) \
103  __sinit(ptr); \
104  } while (0)
105 
106 /* Return true iff the given FILE cannot be written now. */
107 
108 #define cantwrite(ptr, fp) \
109  ((((fp)->_flags & __SWR) == 0 || (fp)->_bf._base == NULL) && \
110  __swsetup_r(ptr, fp))
111 
112 /* Test whether the given stdio file has an active ungetc buffer;
113  release such a buffer, without restoring ordinary unread data. */
114 
115 #define HASUB(fp) ((fp)->_ub._base != NULL)
116 #define FREEUB(ptr, fp) \
117  { \
118  if ((fp)->_ub._base != (fp)->_ubuf) \
119  _free_r(ptr, (char *) (fp)->_ub._base); \
120  (fp)->_ub._base = NULL; \
121  }
122 
123 /* Test for an fgetline() buffer. */
124 
125 #define HASLB(fp) ((fp)->_lb._base != NULL)
126 #define FREELB(ptr, fp) \
127  { \
128  _free_r(ptr, (char *) (fp)->_lb._base); \
129  (fp)->_lb._base = NULL; \
130  }
131 
132 /*
133  * Set the orientation for a stream. If o > 0, the stream has wide-
134  * orientation. If o < 0, the stream has byte-orientation.
135  */
136 #define ORIENT(fp, ori) \
137  do \
138  { \
139  if (!((fp)->_flags & __SORD)) \
140  { \
141  (fp)->_flags |= __SORD; \
142  if (ori > 0) \
143  (fp)->_flags2 |= __SWID; \
144  else \
145  (fp)->_flags2 &= ~__SWID; \
146  } \
147  } while (0)
148 
149 /* WARNING: _dcvt is defined in the stdlib directory, not here! */
150 
151 char *_EXFUN(_dcvt, (struct _reent *, char *, double, int, int, char, int) );
152 char *_EXFUN(_sicvt, (char *, short, char) );
153 char *_EXFUN(_icvt, (char *, int, char) );
154 char *_EXFUN(_licvt, (char *, long, char) );
155 #ifdef __GNUC__
156 char *_EXFUN(_llicvt, (char *, long long, char) );
157 #endif
158 
159 #define CVT_BUF_SIZE 128
160 
161 #define NDYNAMIC 4 /* add four more whenever necessary */
162 
163 #ifdef __SINGLE_THREAD__
164 #define __sfp_lock_acquire()
165 #define __sfp_lock_release()
166 #define __sinit_lock_acquire()
167 #define __sinit_lock_release()
168 #else
169 _VOID _EXFUN(__sfp_lock_acquire, (_VOID));
170 _VOID _EXFUN(__sfp_lock_release, (_VOID));
171 _VOID _EXFUN(__sinit_lock_acquire, (_VOID));
172 _VOID _EXFUN(__sinit_lock_release, (_VOID));
173 #endif