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