1 | /*- |
---|
2 | * Copyright (c) 1990, 1993 |
---|
3 | * The Regents of the University of California. All rights reserved. |
---|
4 | * |
---|
5 | * This code is derived from software contributed to Berkeley by |
---|
6 | * Chris Torek. |
---|
7 | * |
---|
8 | * Copyright (c) 2011 The FreeBSD Foundation |
---|
9 | * All rights reserved. |
---|
10 | * Portions of this software were developed by David Chisnall |
---|
11 | * under sponsorship from the FreeBSD Foundation. |
---|
12 | * |
---|
13 | * Redistribution and use in source and binary forms, with or without |
---|
14 | * modification, are permitted provided that the following conditions |
---|
15 | * are met: |
---|
16 | * 1. Redistributions of source code must retain the above copyright |
---|
17 | * notice, this list of conditions and the following disclaimer. |
---|
18 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
19 | * notice, this list of conditions and the following disclaimer in the |
---|
20 | * documentation and/or other materials provided with the distribution. |
---|
21 | * 4. Neither the name of the University nor the names of its contributors |
---|
22 | * may be used to endorse or promote products derived from this software |
---|
23 | * without specific prior written permission. |
---|
24 | * |
---|
25 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
---|
26 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
---|
29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
---|
30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
---|
31 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
32 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
---|
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
---|
34 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
---|
35 | * SUCH DAMAGE. |
---|
36 | * |
---|
37 | * @(#)local.h 8.3 (Berkeley) 7/3/94 |
---|
38 | * $FreeBSD$ |
---|
39 | */ |
---|
40 | |
---|
41 | #include <sys/types.h> /* for off_t */ |
---|
42 | #include <pthread.h> |
---|
43 | #include <string.h> |
---|
44 | #include <wchar.h> |
---|
45 | #include <locale.h> |
---|
46 | |
---|
47 | /* |
---|
48 | * Information local to this implementation of stdio, |
---|
49 | * in particular, macros and private variables. |
---|
50 | */ |
---|
51 | |
---|
52 | extern int _sread(FILE *, char *, int); |
---|
53 | extern int _swrite(FILE *, char const *, int); |
---|
54 | extern fpos_t _sseek(FILE *, fpos_t, int); |
---|
55 | extern int _ftello(FILE *, fpos_t *); |
---|
56 | extern int _fseeko(FILE *, off_t, int, int); |
---|
57 | extern int __fflush(FILE *fp); |
---|
58 | extern void __fcloseall(void); |
---|
59 | #ifndef __rtems__ |
---|
60 | extern wint_t __fgetwc(FILE *, locale_t); |
---|
61 | extern wint_t __fputwc(wchar_t, FILE *, locale_t); |
---|
62 | #endif /* __rtems__ */ |
---|
63 | extern int __sflush(FILE *); |
---|
64 | extern FILE *__sfp(void); |
---|
65 | extern int __slbexpand(FILE *, size_t); |
---|
66 | #ifndef __rtems__ |
---|
67 | extern int __srefill(FILE *); |
---|
68 | #else |
---|
69 | /* |
---|
70 | * __srefill is used by fgetln(). The method is in newlib but the |
---|
71 | * prototype is in a private .h which is not installed. |
---|
72 | * allows it to be pulled from newlib. |
---|
73 | */ |
---|
74 | extern int __srefill_r(struct _reent *,FILE *); |
---|
75 | |
---|
76 | #define __srefill(_x) __srefill_r(__getreent(), _x) |
---|
77 | #endif |
---|
78 | extern int __sread(void *, char *, int); |
---|
79 | extern int __swrite(void *, char const *, int); |
---|
80 | extern fpos_t __sseek(void *, fpos_t, int); |
---|
81 | extern int __sclose(void *); |
---|
82 | extern void __sinit(void); |
---|
83 | extern void _cleanup(void); |
---|
84 | extern void __smakebuf(FILE *); |
---|
85 | extern int __swhatbuf(FILE *, size_t *, int *); |
---|
86 | extern int _fwalk(int (*)(FILE *)); |
---|
87 | #ifndef __rtems__ |
---|
88 | extern int __svfscanf(FILE *, locale_t, const char *, __va_list); |
---|
89 | #endif /* __rtems__ */ |
---|
90 | extern int __swsetup(FILE *); |
---|
91 | extern int __sflags(const char *, int *); |
---|
92 | extern int __ungetc(int, FILE *); |
---|
93 | #ifndef __rtems__ |
---|
94 | extern wint_t __ungetwc(wint_t, FILE *, locale_t); |
---|
95 | extern int __vfprintf(FILE *, locale_t, const char *, __va_list); |
---|
96 | #endif /* __rtems__ */ |
---|
97 | extern int __vfscanf(FILE *, const char *, __va_list); |
---|
98 | #ifndef __rtems__ |
---|
99 | extern int __vfwprintf(FILE *, locale_t, const wchar_t *, __va_list); |
---|
100 | extern int __vfwscanf(FILE * __restrict, locale_t, const wchar_t * __restrict, |
---|
101 | __va_list); |
---|
102 | #endif /* __rtems__ */ |
---|
103 | extern size_t __fread(void * __restrict buf, size_t size, size_t count, |
---|
104 | FILE * __restrict fp); |
---|
105 | extern int __sdidinit; |
---|
106 | |
---|
107 | |
---|
108 | /* |
---|
109 | * Prepare the given FILE for writing, and return 0 iff it |
---|
110 | * can be written now. Otherwise, return EOF and set errno. |
---|
111 | */ |
---|
112 | #define prepwrite(fp) \ |
---|
113 | ((((fp)->_flags & __SWR) == 0 || \ |
---|
114 | ((fp)->_bf._base == NULL && ((fp)->_flags & __SSTR) == 0)) && \ |
---|
115 | __swsetup(fp)) |
---|
116 | |
---|
117 | /* |
---|
118 | * Test whether the given stdio file has an active ungetc buffer; |
---|
119 | * release such a buffer, without restoring ordinary unread data. |
---|
120 | */ |
---|
121 | #define HASUB(fp) ((fp)->_ub._base != NULL) |
---|
122 | #define FREEUB(fp) { \ |
---|
123 | if ((fp)->_ub._base != (fp)->_ubuf) \ |
---|
124 | free((char *)(fp)->_ub._base); \ |
---|
125 | (fp)->_ub._base = NULL; \ |
---|
126 | } |
---|
127 | |
---|
128 | /* |
---|
129 | * test for an fgetln() buffer. |
---|
130 | */ |
---|
131 | #define HASLB(fp) ((fp)->_lb._base != NULL) |
---|
132 | #define FREELB(fp) { \ |
---|
133 | free((char *)(fp)->_lb._base); \ |
---|
134 | (fp)->_lb._base = NULL; \ |
---|
135 | } |
---|
136 | |
---|
137 | /* |
---|
138 | * Structure initializations for 'fake' FILE objects. |
---|
139 | */ |
---|
140 | #define FAKE_FILE { \ |
---|
141 | ._file = -1, \ |
---|
142 | ._fl_mutex = PTHREAD_MUTEX_INITIALIZER, \ |
---|
143 | } |
---|
144 | |
---|
145 | /* |
---|
146 | * Set the orientation for a stream. If o > 0, the stream has wide- |
---|
147 | * orientation. If o < 0, the stream has byte-orientation. |
---|
148 | */ |
---|
149 | #ifdef __rtems__ |
---|
150 | #define ORIENT(fp, o) |
---|
151 | #else |
---|
152 | #define ORIENT(fp, o) do { \ |
---|
153 | if ((fp)->_orientation == 0) \ |
---|
154 | (fp)->_orientation = (o); \ |
---|
155 | } while (0) |
---|
156 | #endif |
---|