xref: /illumos-gate/usr/src/contrib/ast/src/lib/libast/include/sfio_t.h (revision b30d193948be5a7794d7ae3ba0ed9c2f72c88e0f)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1985-2012 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                 Eclipse Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *          http://www.eclipse.org/org/documents/epl-v10.html           *
11 *         (with md5 checksum b35adb5213ca9657e911e9befb180842)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *                 Glenn Fowler <gsf@research.att.com>                  *
18 *                  David Korn <dgk@research.att.com>                   *
19 *                   Phong Vo <kpv@research.att.com>                    *
20 *                                                                      *
21 ***********************************************************************/
22 #ifndef _SFIO_T_H
23 #define _SFIO_T_H	1
24 
25 /*	This header file is for library writers who need to know certain
26 **	internal info concerning the full Sfio_t structure. Including this
27 **	file means that you agree to track closely with sfio development
28 **	in case its internal architecture is changed.
29 **
30 **	Written by Kiem-Phong Vo
31 */
32 
33 /* the parts of Sfio_t private to sfio functions */
34 #define _SFIO_PRIVATE \
35 	Sfoff_t			extent;	/* current file	size		*/ \
36 	Sfoff_t			here;	/* current physical location	*/ \
37 	unsigned char		unused_1;/* unused #1			*/ \
38 	unsigned char		tiny[1];/* for unbuffered read stream	*/ \
39 	unsigned short		bits;	/* private flags		*/ \
40 	unsigned int		mode;	/* current io mode		*/ \
41 	struct _sfdisc_s*	disc;	/* discipline			*/ \
42 	struct _sfpool_s*	pool;	/* the pool containing this	*/ \
43 	struct _sfrsrv_s*	rsrv;	/* reserved buffer		*/ \
44 	struct _sfproc_s*	proc;	/* coprocess id, etc.		*/ \
45 	Void_t*			mutex;	/* mutex for thread-safety	*/ \
46 	Void_t*			stdio;	/* stdio FILE if any		*/ \
47 	Sfoff_t			lpos;	/* last seek position		*/ \
48 	size_t			iosz;	/* preferred size for I/O	*/ \
49 	size_t			blksz;	/* preferred block size		*/ \
50 	int			getr;	/* the last sfgetr separator 	*/ \
51 	_SFIO_PRIVATE_PAD
52 
53 #if _ast_sizeof_pointer == 8
54 #define _SFIO_PRIVATE_PAD	int pad;
55 #else
56 #define _SFIO_PRIVATE_PAD
57 #endif
58 
59 #include	"sfio.h"
60 
61 /* mode bit to indicate that the structure hasn't been initialized */
62 #define SF_INIT		0000004
63 #define SF_DCDOWN	00010000
64 
65 /* short-hand for common stream types */
66 #define SF_RDWR		(SF_READ|SF_WRITE)
67 #define SF_RDSTR	(SF_READ|SF_STRING)
68 #define SF_WRSTR	(SF_WRITE|SF_STRING)
69 #define SF_RDWRSTR	(SF_RDWR|SF_STRING)
70 
71 /* for static initialization of an Sfio_t structure */
72 #define SFNEW(data,size,file,type,disc,mutex)	\
73 	{ (unsigned char*)(data),			/* next		*/ \
74 	  (unsigned char*)(data),			/* endw		*/ \
75 	  (unsigned char*)(data),			/* endr		*/ \
76 	  (unsigned char*)(data),			/* endb		*/ \
77 	  (Sfio_t*)0,					/* push		*/ \
78 	  (unsigned short)((type)&SF_FLAGS),		/* flags	*/ \
79 	  (short)(file),				/* file		*/ \
80 	  (unsigned char*)(data),			/* data		*/ \
81 	  (ssize_t)(size),				/* size		*/ \
82 	  (ssize_t)(-1),				/* val		*/ \
83 	  (Sfoff_t)0,					/* extent	*/ \
84 	  (Sfoff_t)0,					/* here		*/ \
85 	  0,						/* getr		*/ \
86 	  {0},						/* tiny		*/ \
87 	  0,						/* bits		*/ \
88 	  (unsigned int)(((type)&(SF_RDWR))|SF_INIT),	/* mode		*/ \
89 	  (struct _sfdisc_s*)(disc),			/* disc		*/ \
90 	  (struct _sfpool_s*)0,				/* pool		*/ \
91 	  (struct _sfrsrv_s*)0,				/* rsrv		*/ \
92 	  (struct _sfproc_s*)0,				/* proc		*/ \
93 	  (mutex),					/* mutex	*/ \
94 	  (Void_t*)0,					/* stdio	*/ \
95 	  (Sfoff_t)0,					/* lpos		*/ \
96 	  (size_t)0					/* iosz		*/ \
97 	}
98 
99 /* function to clear an Sfio_t structure */
100 #define SFCLEAR(f,mtx) \
101 	( (f)->next = (unsigned char*)0,		/* next		*/ \
102 	  (f)->endw = (unsigned char*)0,		/* endw		*/ \
103 	  (f)->endr = (unsigned char*)0,		/* endr		*/ \
104 	  (f)->endb = (unsigned char*)0,		/* endb		*/ \
105 	  (f)->push = (Sfio_t*)0,			/* push		*/ \
106 	  (f)->flags = (unsigned short)0,		/* flags	*/ \
107 	  (f)->file = -1,				/* file		*/ \
108 	  (f)->data = (unsigned char*)0,		/* data		*/ \
109 	  (f)->size = (ssize_t)(-1),			/* size		*/ \
110 	  (f)->val = (ssize_t)(-1),			/* val		*/ \
111 	  (f)->extent = (Sfoff_t)(-1),			/* extent	*/ \
112 	  (f)->here = (Sfoff_t)0,			/* here		*/ \
113 	  (f)->getr = 0,				/* getr		*/ \
114 	  (f)->tiny[0] = 0,				/* tiny		*/ \
115 	  (f)->bits = 0,				/* bits		*/ \
116 	  (f)->mode = 0,				/* mode		*/ \
117 	  (f)->disc = (struct _sfdisc_s*)0,		/* disc		*/ \
118 	  (f)->pool = (struct _sfpool_s*)0,		/* pool		*/ \
119 	  (f)->rsrv = (struct _sfrsrv_s*)0,		/* rsrv		*/ \
120 	  (f)->proc = (struct _sfproc_s*)0,		/* proc		*/ \
121 	  (f)->mutex = (mtx),				/* mutex	*/ \
122 	  (f)->stdio = (Void_t*)0,			/* stdio	*/ \
123 	  (f)->lpos = (Sfoff_t)0,			/* lpos		*/ \
124 	  (f)->iosz = (size_t)0				/* iosz		*/ \
125 	)
126 
127 /* expose next stream inside discipline function; state saved in int f */
128 #define SFDCNEXT(sp,f)	(((f)=(sp)->bits&SF_DCDOWN),(sp)->bits|=SF_DCDOWN)
129 
130 /* restore SFDCNEXT() state from int f */
131 #define SFDCPREV(sp,f)	((f)?(0):((sp)->bits&=~SF_DCDOWN))
132 
133 #endif /* _SFIO_T_H */
134