xref: /titanic_41/usr/src/lib/libast/common/include/sfio_t.h (revision bda1f129971950880940a17bab0bf096d5744b0c)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1985-2008 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                  Common Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *            http://www.opensource.org/licenses/cpl1.0.txt             *
11 *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
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		getr;	/* the last sfgetr separator 	*/ \
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 	Void_t*			fill[1];/* modest expansion		*/
51 
52 #include	"sfio.h"
53 
54 /* mode bit to indicate that the structure hasn't been initialized */
55 #define SF_INIT		0000004
56 #define SF_DCDOWN	00010000
57 
58 /* short-hand for common stream types */
59 #define SF_RDWR		(SF_READ|SF_WRITE)
60 #define SF_RDSTR	(SF_READ|SF_STRING)
61 #define SF_WRSTR	(SF_WRITE|SF_STRING)
62 #define SF_RDWRSTR	(SF_RDWR|SF_STRING)
63 
64 /* for static initialization of an Sfio_t structure */
65 #define SFNEW(data,size,file,type,disc,mutex)	\
66 	{ (unsigned char*)(data),			/* next		*/ \
67 	  (unsigned char*)(data),			/* endw		*/ \
68 	  (unsigned char*)(data),			/* endr		*/ \
69 	  (unsigned char*)(data),			/* endb		*/ \
70 	  (Sfio_t*)0,					/* push		*/ \
71 	  (unsigned short)((type)&SF_FLAGS),		/* flags	*/ \
72 	  (short)(file),				/* file		*/ \
73 	  (unsigned char*)(data),			/* data		*/ \
74 	  (ssize_t)(size),				/* size		*/ \
75 	  (ssize_t)(-1),				/* val		*/ \
76 	  (Sfoff_t)0,					/* extent	*/ \
77 	  (Sfoff_t)0,					/* here		*/ \
78 	  0,						/* getr		*/ \
79 	  {0},						/* tiny		*/ \
80 	  0,						/* bits		*/ \
81 	  (unsigned int)(((type)&(SF_RDWR))|SF_INIT),	/* mode		*/ \
82 	  (struct _sfdisc_s*)(disc),			/* disc		*/ \
83 	  (struct _sfpool_s*)0,				/* pool		*/ \
84 	  (struct _sfrsrv_s*)0,				/* rsrv		*/ \
85 	  (struct _sfproc_s*)0,				/* proc		*/ \
86 	  (mutex),					/* mutex	*/ \
87 	  (Void_t*)0,					/* stdio	*/ \
88 	  (Sfoff_t)0,					/* lpos		*/ \
89 	  (size_t)0					/* iosz		*/ \
90 	}
91 
92 /* function to clear an Sfio_t structure */
93 #define SFCLEAR(f,mtx) \
94 	( (f)->next = (unsigned char*)0,		/* next		*/ \
95 	  (f)->endw = (unsigned char*)0,		/* endw		*/ \
96 	  (f)->endr = (unsigned char*)0,		/* endr		*/ \
97 	  (f)->endb = (unsigned char*)0,		/* endb		*/ \
98 	  (f)->push = (Sfio_t*)0,			/* push		*/ \
99 	  (f)->flags = (unsigned short)0,		/* flags	*/ \
100 	  (f)->file = -1,				/* file		*/ \
101 	  (f)->data = (unsigned char*)0,		/* data		*/ \
102 	  (f)->size = (ssize_t)(-1),			/* size		*/ \
103 	  (f)->val = (ssize_t)(-1),			/* val		*/ \
104 	  (f)->extent = (Sfoff_t)(-1),			/* extent	*/ \
105 	  (f)->here = (Sfoff_t)0,			/* here		*/ \
106 	  (f)->getr = 0,				/* getr		*/ \
107 	  (f)->tiny[0] = 0,				/* tiny		*/ \
108 	  (f)->bits = 0,				/* bits		*/ \
109 	  (f)->mode = 0,				/* mode		*/ \
110 	  (f)->disc = (struct _sfdisc_s*)0,		/* disc		*/ \
111 	  (f)->pool = (struct _sfpool_s*)0,		/* pool		*/ \
112 	  (f)->rsrv = (struct _sfrsrv_s*)0,		/* rsrv		*/ \
113 	  (f)->proc = (struct _sfproc_s*)0,		/* proc		*/ \
114 	  (f)->mutex = (mtx),				/* mutex	*/ \
115 	  (f)->stdio = (Void_t*)0,			/* stdio	*/ \
116 	  (f)->lpos = (Sfoff_t)0,			/* lpos		*/ \
117 	  (f)->iosz = (size_t)0				/* iosz		*/ \
118 	)
119 
120 /* expose next stream inside discipline function; state saved in int f */
121 #define SFDCNEXT(sp,f)	(((f)=(sp)->bits&SF_DCDOWN),(sp)->bits|=SF_DCDOWN)
122 
123 /* restore SFDCNEXT() state from int f */
124 #define SFDCPREV(sp,f)	((f)?(0):((sp)->bits&=~SF_DCDOWN))
125 
126 #endif /* _SFIO_T_H */
127