Deleted Added
full compact
local.h (165903) local.h (178287)
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 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 4. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 * @(#)local.h 8.3 (Berkeley) 7/3/94
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 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 4. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 * @(#)local.h 8.3 (Berkeley) 7/3/94
33 * $FreeBSD: head/lib/libc/stdio/local.h 165903 2007-01-09 00:28:16Z imp $
33 * $FreeBSD: head/lib/libc/stdio/local.h 178287 2008-04-17 22:17:54Z jhb $
34 */
35
36#include <sys/types.h> /* for off_t */
37#include <pthread.h>
38#include <string.h>
39#include <wchar.h>
40
41/*
42 * Information local to this implementation of stdio,
43 * in particular, macros and private variables.
44 */
45
46extern int _sread(FILE *, char *, int);
47extern int _swrite(FILE *, char const *, int);
48extern fpos_t _sseek(FILE *, fpos_t, int);
49extern int _ftello(FILE *, fpos_t *);
50extern int _fseeko(FILE *, off_t, int, int);
51extern int __fflush(FILE *fp);
52extern void __fcloseall(void);
53extern wint_t __fgetwc(FILE *);
54extern wint_t __fputwc(wchar_t, FILE *);
55extern int __sflush(FILE *);
56extern FILE *__sfp(void);
57extern int __slbexpand(FILE *, size_t);
58extern int __srefill(FILE *);
59extern int __sread(void *, char *, int);
60extern int __swrite(void *, char const *, int);
61extern fpos_t __sseek(void *, fpos_t, int);
62extern int __sclose(void *);
63extern void __sinit(void);
64extern void _cleanup(void);
65extern void __smakebuf(FILE *);
66extern int __swhatbuf(FILE *, size_t *, int *);
67extern int _fwalk(int (*)(FILE *));
68extern int __svfscanf(FILE *, const char *, __va_list);
69extern int __swsetup(FILE *);
70extern int __sflags(const char *, int *);
71extern int __ungetc(int, FILE *);
72extern wint_t __ungetwc(wint_t, FILE *);
73extern int __vfprintf(FILE *, const char *, __va_list);
74extern int __vfscanf(FILE *, const char *, __va_list);
75extern int __vfwprintf(FILE *, const wchar_t *, __va_list);
76extern int __vfwscanf(FILE * __restrict, const wchar_t * __restrict,
77 __va_list);
78extern size_t __fread(void * __restrict buf, size_t size, size_t count,
79 FILE * __restrict fp);
80extern int __sdidinit;
81
82
34 */
35
36#include <sys/types.h> /* for off_t */
37#include <pthread.h>
38#include <string.h>
39#include <wchar.h>
40
41/*
42 * Information local to this implementation of stdio,
43 * in particular, macros and private variables.
44 */
45
46extern int _sread(FILE *, char *, int);
47extern int _swrite(FILE *, char const *, int);
48extern fpos_t _sseek(FILE *, fpos_t, int);
49extern int _ftello(FILE *, fpos_t *);
50extern int _fseeko(FILE *, off_t, int, int);
51extern int __fflush(FILE *fp);
52extern void __fcloseall(void);
53extern wint_t __fgetwc(FILE *);
54extern wint_t __fputwc(wchar_t, FILE *);
55extern int __sflush(FILE *);
56extern FILE *__sfp(void);
57extern int __slbexpand(FILE *, size_t);
58extern int __srefill(FILE *);
59extern int __sread(void *, char *, int);
60extern int __swrite(void *, char const *, int);
61extern fpos_t __sseek(void *, fpos_t, int);
62extern int __sclose(void *);
63extern void __sinit(void);
64extern void _cleanup(void);
65extern void __smakebuf(FILE *);
66extern int __swhatbuf(FILE *, size_t *, int *);
67extern int _fwalk(int (*)(FILE *));
68extern int __svfscanf(FILE *, const char *, __va_list);
69extern int __swsetup(FILE *);
70extern int __sflags(const char *, int *);
71extern int __ungetc(int, FILE *);
72extern wint_t __ungetwc(wint_t, FILE *);
73extern int __vfprintf(FILE *, const char *, __va_list);
74extern int __vfscanf(FILE *, const char *, __va_list);
75extern int __vfwprintf(FILE *, const wchar_t *, __va_list);
76extern int __vfwscanf(FILE * __restrict, const wchar_t * __restrict,
77 __va_list);
78extern size_t __fread(void * __restrict buf, size_t size, size_t count,
79 FILE * __restrict fp);
80extern int __sdidinit;
81
82
83/* hold a buncha junk that would grow the ABI */
84struct __sFILEX {
85 unsigned char *_up; /* saved _p when _p is doing ungetc data */
86 pthread_mutex_t fl_mutex; /* used for MT-safety */
87 pthread_t fl_owner; /* current owner */
88 int fl_count; /* recursive lock count */
89 int orientation; /* orientation for fwide() */
90 mbstate_t mbstate; /* multibyte conversion state */
91};
92
93/*
94 * Prepare the given FILE for writing, and return 0 iff it
95 * can be written now. Otherwise, return EOF and set errno.
96 */
97#define prepwrite(fp) \
98 ((((fp)->_flags & __SWR) == 0 || \
99 ((fp)->_bf._base == NULL && ((fp)->_flags & __SSTR) == 0)) && \
100 __swsetup(fp))
101
102/*
103 * Test whether the given stdio file has an active ungetc buffer;
104 * release such a buffer, without restoring ordinary unread data.
105 */
106#define HASUB(fp) ((fp)->_ub._base != NULL)
107#define FREEUB(fp) { \
108 if ((fp)->_ub._base != (fp)->_ubuf) \
109 free((char *)(fp)->_ub._base); \
110 (fp)->_ub._base = NULL; \
111}
112
113/*
114 * test for an fgetln() buffer.
115 */
116#define HASLB(fp) ((fp)->_lb._base != NULL)
117#define FREELB(fp) { \
118 free((char *)(fp)->_lb._base); \
119 (fp)->_lb._base = NULL; \
120}
121
83/*
84 * Prepare the given FILE for writing, and return 0 iff it
85 * can be written now. Otherwise, return EOF and set errno.
86 */
87#define prepwrite(fp) \
88 ((((fp)->_flags & __SWR) == 0 || \
89 ((fp)->_bf._base == NULL && ((fp)->_flags & __SSTR) == 0)) && \
90 __swsetup(fp))
91
92/*
93 * Test whether the given stdio file has an active ungetc buffer;
94 * release such a buffer, without restoring ordinary unread data.
95 */
96#define HASUB(fp) ((fp)->_ub._base != NULL)
97#define FREEUB(fp) { \
98 if ((fp)->_ub._base != (fp)->_ubuf) \
99 free((char *)(fp)->_ub._base); \
100 (fp)->_ub._base = NULL; \
101}
102
103/*
104 * test for an fgetln() buffer.
105 */
106#define HASLB(fp) ((fp)->_lb._base != NULL)
107#define FREELB(fp) { \
108 free((char *)(fp)->_lb._base); \
109 (fp)->_lb._base = NULL; \
110}
111
122#define INITEXTRA(fp) { \
123 (fp)->_extra->_up = NULL; \
124 (fp)->_extra->fl_mutex = PTHREAD_MUTEX_INITIALIZER; \
125 (fp)->_extra->fl_owner = NULL; \
126 (fp)->_extra->fl_count = 0; \
127 (fp)->_extra->orientation = 0; \
128 memset(&(fp)->_extra->mbstate, 0, sizeof(mbstate_t)); \
129}
130
131/*
132 * Set the orientation for a stream. If o > 0, the stream has wide-
133 * orientation. If o < 0, the stream has byte-orientation.
134 */
135#define ORIENT(fp, o) do { \
112/*
113 * Set the orientation for a stream. If o > 0, the stream has wide-
114 * orientation. If o < 0, the stream has byte-orientation.
115 */
116#define ORIENT(fp, o) do { \
136 if ((fp)->_extra->orientation == 0) \
137 (fp)->_extra->orientation = (o); \
117 if ((fp)->_orientation == 0) \
118 (fp)->_orientation = (o); \
138} while (0)
119} while (0)