2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
8 * Copyright (c) 2011 The FreeBSD Foundation
10 * Portions of this software were developed by David Chisnall
11 * under sponsorship from the FreeBSD Foundation.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
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 * 3. 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.
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
37 * @(#)local.h 8.3 (Berkeley) 7/3/94
38 * $FreeBSD: head/lib/libc/stdio/local.h 234799 2012-04-29 16:28:39Z das $
41 #include <sys/types.h> /* for off_t */
45 #include <xlocale_private.h>
47 #include "priv_stdio.h"
51 * Information local to this implementation of stdio,
52 * in particular, macros and private variables.
55 extern int _sread(FILE *, char *, int);
56 extern int _swrite(FILE *, char const *, int);
57 extern fpos_t _sseek(FILE *, fpos_t, int);
58 extern int _ftello(FILE *, fpos_t *);
59 extern int _fseeko(FILE *, off_t
, int, int);
60 extern int __fflush(FILE *fp
);
61 extern void __fcloseall(void);
62 extern wint_t __fgetwc_mbs(FILE *, mbstate_t *, int *, locale_t
);
63 extern wint_t __fputwc(wchar_t, FILE *, locale_t
);
64 extern int __sflush(FILE *);
65 extern FILE *__sfp(void);
66 extern int __slbexpand(FILE *, size_t);
67 extern int __srefill(FILE *);
68 extern int __sread(void *, char *, int);
69 extern int __swrite(void *, char const *, int);
70 extern fpos_t __sseek(void *, fpos_t, int);
71 extern int __sclose(void *);
72 extern void __sinit(void);
73 extern void _cleanup(void);
74 extern void __smakebuf(FILE *);
75 extern int __swhatbuf(FILE *, size_t *, int *);
76 extern int _fwalk(int (*)(FILE *));
77 extern int __svfscanf(FILE *, locale_t
, const char *, __va_list
);
78 extern int __swsetup(FILE *);
79 extern int __sflags(const char *, int *);
80 extern int __ungetc(int, FILE *);
81 extern wint_t __ungetwc(wint_t, FILE *, locale_t
);
82 extern int __vfprintf(FILE *, locale_t
, const char *, __va_list
);
83 extern int __vfscanf(FILE *, const char *, __va_list
);
84 extern int __vfwprintf(FILE *, locale_t
, const wchar_t *, __va_list
);
85 extern int __vfwscanf(FILE * __restrict
, locale_t
, const wchar_t * __restrict
,
87 extern size_t __fread(void * __restrict buf
, size_t size
, size_t count
,
88 FILE * __restrict fp
);
89 extern int __sdidinit
;
92 __fgetwc(FILE *fp
, locale_t locale
)
95 struct wchar_io_data
*wcio
;
98 _SET_ORIENTATION(fp
,1);
104 wcio
->wcio_ungetwc_inbuf
= 0;
105 st
= &wcio
->wcio_mbstate_out
;
107 return (__fgetwc_mbs(fp
, st
, &nread
, locale
));
111 * Prepare the given FILE for writing, and return 0 iff it
112 * can be written now. Otherwise, return EOF and set errno.
114 #define prepwrite(fp) \
115 ((((fp)->pub._flags & __SWR) == 0 || \
116 ((fp)->_bf._base == NULL && ((fp)->pub._flags & __SSTR) == 0)) && \
120 * Test whether the given stdio file has an active ungetc buffer;
121 * release such a buffer, without restoring ordinary unread data.
123 #define HASUB(fp) ((fp)->_ub._base != NULL)
124 #define FREEUB(fp) { \
125 if ((fp)->_ub._base != (fp)->_ubuf) \
126 free((char *)(fp)->_ub._base); \
127 (fp)->_ub._base = NULL; \
131 * test for an fgetln() buffer.
133 #define HASLB(fp) ((fp)->_lb._base != NULL)
134 #define FREELB(fp) { \
135 free((char *)(fp)->_lb._base); \
136 (fp)->_lb._base = NULL; \
140 * Structure initializations for 'fake' FILE objects.
142 #define FAKE_FILE { \
145 ._fl_mutex = PTHREAD_MUTEX_INITIALIZER, \
149 * Set the orientation for a stream. If o > 0, the stream has wide-
150 * orientation. If o < 0, the stream has byte-orientation.
152 #define ORIENT(fp, o) _SET_ORIENTATION(fp, o)