xref: /illumos-gate/usr/src/lib/libc/inc/file64.h (revision 1769817e9676d2db341d2b6828c199f0eabac823)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * Copyright 2020 Robert Mustacchi
29  */
30 
31 /*
32  * This is the header where the internal to libc definition of the FILE
33  * structure is defined. The exrernal defintion defines the FILE structure
34  * as an array of longs. This prevents customers from writing code that
35  * depends upon the implemnetation of stdio. The __fbufsize(3C) man page
36  * documents a set of routines that customers can use so that they do not
37  * need access to the FILE structure.
38  *
39  * When compiling libc this file MUST be included BEFORE <stdio.h>, and
40  * any other headers that themselves directly or indirectly include
41  * <stdio.h>. Failure to do so, will cause the compile of libc to fail,
42  * since the structure members will not be visible to the stdio routines.
43  */
44 
45 #ifndef	_FILE64_H
46 #define	_FILE64_H
47 
48 #include <synch.h>
49 #include <stdio_tag.h>
50 #include <wchar_impl.h>
51 
52 #ifdef	__cplusplus
53 extern "C" {
54 #endif
55 
56 #ifndef	_MBSTATE_T
57 #define	_MBSTATE_T
58 typedef __mbstate_t	mbstate_t;
59 #endif
60 
61 #define	rmutex_t	mutex_t
62 
63 typedef ssize_t (*fread_t)(__FILE *, char *, size_t);
64 typedef ssize_t (*fwrite_t)(__FILE *, const char *, size_t);
65 typedef off_t (*fseek_t)(__FILE *, off_t, int);
66 typedef int (*fclose_t)(__FILE *);
67 
68 typedef struct {
69 	fread_t	std_read;
70 	fwrite_t std_write;
71 	fseek_t std_seek;
72 	fclose_t std_close;
73 	void *std_data;
74 } stdio_ops_t;
75 
76 #ifdef	_LP64
77 
78 /*
79  * This structure cannot grow beyond its current size of 128 bytes. See the file
80  * lib/libc/port/stdio/README.design for more information.
81  */
82 struct __FILE_TAG {
83 	unsigned char	*_ptr;	/* next character from/to here in buffer */
84 	unsigned char	*_base;	/* the buffer */
85 	unsigned char	*_end;	/* the end of the buffer */
86 	ssize_t		_cnt;	/* number of available characters in buffer */
87 	int		_file;	/* UNIX System file descriptor */
88 	unsigned int	_flag;	/* the state of the stream */
89 	rmutex_t	_lock;	/* lock for this structure */
90 	mbstate_t	_state;	/* mbstate_t */
91 	stdio_ops_t	*_ops;	/* Alternate impl ops */
92 	char		__fill[24];	/* filler to bring size to 128 bytes */
93 };
94 
95 #else
96 
97 /*
98  * Stuff missing from our 32-bit FILE struct.
99  */
100 struct xFILEdata {
101 	uintptr_t	_magic;	/* Check: magic number, must be first */
102 	unsigned char	*_end;	/* the end of the buffer */
103 	rmutex_t	_lock;	/* lock for this structure */
104 	mbstate_t	_state;	/* mbstate_t */
105 	int		_altfd;	/* alternate fd if > 255 */
106 	stdio_ops_t	*_ops;	/* Alternate impl ops */
107 };
108 
109 #define	XFILEINITIALIZER	{ 0, NULL, RECURSIVEMUTEX, DEFAULTMBSTATE }
110 
111 #endif	/*	_LP64	*/
112 
113 #ifdef	__cplusplus
114 }
115 #endif
116 
117 #endif	/* _FILE64_H */
118