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