xref: /titanic_41/usr/src/lib/libast/i386/include/ast/sfio.h (revision 9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bb)
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_H
23 #define _SFIO_H	1
24 
25 #define SFIO_VERSION	20080717L
26 
27 /*	Public header file for the sfio library
28 **
29 **	Written by Kiem-Phong Vo
30 */
31 
32 typedef struct _sfio_s		Sfio_t;
33 typedef struct _sfdisc_s	Sfdisc_t;
34 
35 #if defined(_AST_STD_H) || defined(_PACKAGE_ast) && defined(_SFIO_PRIVATE)
36 #include	<ast_std.h>
37 #else
38 #include	<ast_common.h>
39 #endif /* _PACKAGE_ast */
40 
41 /* Sfoff_t should be large enough for largest file address */
42 #define Sfoff_t		intmax_t
43 #define Sflong_t	intmax_t
44 #define Sfulong_t	uintmax_t
45 #define Sfdouble_t	_ast_fltmax_t
46 
47 typedef ssize_t		(*Sfread_f)_ARG_((Sfio_t*, Void_t*, size_t, Sfdisc_t*));
48 typedef ssize_t		(*Sfwrite_f)_ARG_((Sfio_t*, const Void_t*, size_t, Sfdisc_t*));
49 typedef Sfoff_t		(*Sfseek_f)_ARG_((Sfio_t*, Sfoff_t, int, Sfdisc_t*));
50 typedef int		(*Sfexcept_f)_ARG_((Sfio_t*, int, Void_t*, Sfdisc_t*));
51 
52 /* discipline structure */
53 struct _sfdisc_s
54 {	Sfread_f	readf;		/* read function		*/
55 	Sfwrite_f	writef;		/* write function		*/
56 	Sfseek_f	seekf;		/* seek function		*/
57 	Sfexcept_f	exceptf;	/* to handle exceptions		*/
58 	Sfdisc_t*	disc;		/* the continuing discipline	*/
59 };
60 
61 #include <sfio_s.h>
62 
63 /* formatting environment */
64 typedef struct _sffmt_s	Sffmt_t;
65 typedef int		(*Sffmtext_f)_ARG_((Sfio_t*, Void_t*, Sffmt_t*));
66 typedef int		(*Sffmtevent_f)_ARG_((Sfio_t*, int, Void_t*, Sffmt_t*));
67 struct _sffmt_s
68 {	long		version;/* version of this structure		*/
69 	Sffmtext_f	extf;	/* function to process arguments	*/
70 	Sffmtevent_f	eventf;	/* process events			*/
71 
72 	char*		form;	/* format string to stack		*/
73 	va_list	args;	/* corresponding arg list		*/
74 
75 	int		fmt;	/* format character			*/
76 	ssize_t		size;	/* object size				*/
77 	int		flags;	/* formatting flags			*/
78 	int		width;	/* width of field			*/
79 	int		precis;	/* precision required			*/
80 	int		base;	/* conversion base			*/
81 
82 	char*		t_str;	/* type string 				*/
83 	ssize_t		n_str;	/* length of t_str 			*/
84 
85 	Void_t*		mbs;	/* multibyte state for format string	*/
86 
87 	Void_t*		none;	/* unused for now			*/
88 };
89 #define sffmtversion(fe,type) \
90 		((type) ? ((fe)->version = SFIO_VERSION) : (fe)->version)
91 
92 #define SFFMT_SSHORT	000000010 /* 'hh' flag, char			*/
93 #define SFFMT_TFLAG	000000020 /* 't' flag, ptrdiff_t			*/
94 #define SFFMT_ZFLAG	000000040 /* 'z' flag, size_t			*/
95 
96 #define SFFMT_LEFT	000000100 /* left-justification			*/
97 #define SFFMT_SIGN	000000200 /* must have a sign			*/
98 #define SFFMT_BLANK	000000400 /* if not signed, prepend a blank	*/
99 #define SFFMT_ZERO	000001000 /* zero-padding on the left		*/
100 #define SFFMT_ALTER	000002000 /* alternate formatting		*/
101 #define SFFMT_THOUSAND	000004000 /* thousand grouping			*/
102 #define SFFMT_SKIP	000010000 /* skip assignment in scanf()		*/
103 #define SFFMT_SHORT	000020000 /* 'h' flag				*/
104 #define SFFMT_LONG	000040000 /* 'l' flag				*/
105 #define SFFMT_LLONG	000100000 /* 'll' flag				*/
106 #define SFFMT_LDOUBLE	000200000 /* 'L' flag				*/
107 #define SFFMT_VALUE	000400000 /* value is returned			*/
108 #define SFFMT_ARGPOS	001000000 /* getting arg for $ patterns		*/
109 #define SFFMT_IFLAG	002000000 /* 'I' flag				*/
110 #define SFFMT_JFLAG	004000000 /* 'j' flag, intmax_t			*/
111 #define SFFMT_CENTER	010000000 /* '=' flag, center justification	*/
112 #define SFFMT_SET	017777770 /* flags settable on calling extf	*/
113 
114 /* for sfmutex() call */
115 #define SFMTX_LOCK	0	/* up mutex count			*/
116 #define SFMTX_TRYLOCK	1	/* try to up mutex count		*/
117 #define SFMTX_UNLOCK	2	/* down mutex count			*/
118 #define SFMTX_CLRLOCK	3	/* clear mutex count			*/
119 
120 /* various constants */
121 #ifndef NULL
122 #define NULL		0
123 #endif
124 #ifndef EOF
125 #define EOF		(-1)
126 #endif
127 #ifndef SEEK_SET
128 #define SEEK_SET	0
129 #define SEEK_CUR	1
130 #define SEEK_END	2
131 #endif
132 
133 /* bits for various types of files */
134 #define	SF_READ		0000001	/* open for reading			*/
135 #define SF_WRITE	0000002	/* open for writing			*/
136 #define SF_STRING	0000004	/* a string stream			*/
137 #define SF_APPENDWR	0000010	/* file is in append mode only		*/
138 #define SF_MALLOC	0000020	/* buffer is malloc-ed			*/
139 #define SF_LINE		0000040	/* line buffering			*/
140 #define SF_SHARE	0000100	/* stream with shared file descriptor 	*/
141 #define SF_EOF		0000200	/* eof was detected			*/
142 #define SF_ERROR	0000400	/* an error happened			*/
143 #define SF_STATIC	0001000	/* a stream that cannot be freed	*/
144 #define SF_IOCHECK	0002000	/* call exceptf before doing IO		*/
145 #define SF_PUBLIC	0004000	/* SF_SHARE and follow physical seek	*/
146 #define SF_MTSAFE	0010000	/* need thread safety			*/
147 #define SF_WHOLE	0020000	/* preserve wholeness of sfwrite/sfputr */
148 #define SF_IOINTR	0040000	/* return on interrupts			*/
149 #define SF_WCWIDTH	0100000	/* wcwidth display stream		*/
150 
151 #define SF_FLAGS	0177177	/* PUBLIC FLAGS PASSABLE TO SFNEW()	*/
152 #define SF_SETS		0177163	/* flags passable to sfset()		*/
153 
154 #ifndef _SF_NO_OBSOLETE
155 #define SF_BUFCONST	0400000 /* unused flag - for compatibility only	*/
156 #endif
157 
158 /* for sfgetr/sfreserve to hold a record */
159 #define SF_LOCKR	0000010	/* lock record, stop access to stream	*/
160 #define SF_LASTR	0000020	/* get the last incomplete record	*/
161 
162 /* exception events: SF_NEW(0), SF_READ(1), SF_WRITE(2) and the below 	*/
163 #define SF_SEEK		3	/* seek error				*/
164 #define SF_CLOSING	4	/* when stream is about to be closed	*/
165 #define SF_DPUSH	5	/* when discipline is being pushed	*/
166 #define SF_DPOP		6	/* when discipline is being popped	*/
167 #define SF_DPOLL	7	/* see if stream is ready for I/O	*/
168 #define SF_DBUFFER	8	/* buffer not empty during push or pop	*/
169 #define SF_SYNC		9	/* announcing start/end synchronization */
170 #define SF_PURGE	10	/* a sfpurge() call was issued		*/
171 #define SF_FINAL	11	/* closing is done except stream free	*/
172 #define SF_READY	12	/* a polled stream is ready		*/
173 #define SF_LOCKED	13	/* stream is in a locked state		*/
174 #define SF_ATEXIT	14	/* process is exiting			*/
175 #define SF_EVENT	100	/* start of user-defined events		*/
176 
177 /* for stack and disciplines */
178 #define SF_POPSTACK	((Sfio_t*)0)	/* pop the stream stack		*/
179 #define SF_POPDISC	((Sfdisc_t*)0)	/* pop the discipline stack	*/
180 
181 /* for the notify function and discipline exception */
182 #define SF_NEW		0	/* new stream				*/
183 #define SF_SETFD	(-1)	/* about to set the file descriptor 	*/
184 #define SF_MTACCESS	(-2)	/* starting a multi-threaded stream	*/
185 
186 #define SF_BUFSIZE	8192	/* default buffer size			*/
187 #define SF_UNBOUND	(-1)	/* unbounded buffer size		*/
188 
189 /* namespace incursion workarounds -- migrate to the new names */
190 #if !_mac_SF_APPEND
191 #define SF_APPEND	SF_APPENDWR	/* BSDI sys/stat.h		*/
192 #endif
193 #if !_mac_SF_CLOSE
194 #define SF_CLOSE	SF_CLOSING	/* AIX sys/socket.h		*/
195 #endif
196 
197 _BEGIN_EXTERNS_
198 
199 /* standard in/out/err streams */
200 
201 #if _BLD_sfio && defined(__EXPORT__)
202 #define extern		extern __EXPORT__
203 #endif
204 #if !_BLD_sfio && defined(__IMPORT__)
205 #define extern		extern __IMPORT__
206 #endif
207 
208 extern ssize_t		_Sfi;
209 extern ssize_t		_Sfmaxr;
210 
211 extern Sfio_t*		sfstdin;
212 extern Sfio_t*		sfstdout;
213 extern Sfio_t*		sfstderr;
214 
215 #if _UWIN
216 #undef	extern
217 #endif
218 
219 extern Sfio_t		_Sfstdin;
220 extern Sfio_t		_Sfstdout;
221 extern Sfio_t		_Sfstderr;
222 
223 #undef	extern
224 
225 #if _BLD_sfio && defined(__EXPORT__)
226 #define extern	__EXPORT__
227 #endif
228 
229 extern Sfio_t*		sfnew _ARG_((Sfio_t*, Void_t*, size_t, int, int));
230 extern Sfio_t*		sfopen _ARG_((Sfio_t*, const char*, const char*));
231 extern Sfio_t*		sfpopen _ARG_((Sfio_t*, const char*, const char*));
232 extern Sfio_t*		sfstack _ARG_((Sfio_t*, Sfio_t*));
233 extern Sfio_t*		sfswap _ARG_((Sfio_t*, Sfio_t*));
234 extern Sfio_t*		sftmp _ARG_((size_t));
235 extern int		sfpurge _ARG_((Sfio_t*));
236 extern int		sfpoll _ARG_((Sfio_t**, int, int));
237 extern Void_t*		sfreserve _ARG_((Sfio_t*, ssize_t, int));
238 extern int		sfresize _ARG_((Sfio_t*, Sfoff_t));
239 extern int		sfsync _ARG_((Sfio_t*));
240 extern int		sfclrlock _ARG_((Sfio_t*));
241 extern Void_t*		sfsetbuf _ARG_((Sfio_t*, Void_t*, size_t));
242 extern Sfdisc_t*	sfdisc _ARG_((Sfio_t*,Sfdisc_t*));
243 extern int		sfraise _ARG_((Sfio_t*, int, Void_t*));
244 extern int		sfnotify _ARG_((void(*)(Sfio_t*, int, void*)));
245 extern int		sfset _ARG_((Sfio_t*, int, int));
246 extern int		sfsetfd _ARG_((Sfio_t*, int));
247 extern Sfio_t*		sfpool _ARG_((Sfio_t*, Sfio_t*, int));
248 extern ssize_t		sfread _ARG_((Sfio_t*, Void_t*, size_t));
249 extern ssize_t		sfwrite _ARG_((Sfio_t*, const Void_t*, size_t));
250 extern Sfoff_t		sfmove _ARG_((Sfio_t*, Sfio_t*, Sfoff_t, int));
251 extern int		sfclose _ARG_((Sfio_t*));
252 extern Sfoff_t		sftell _ARG_((Sfio_t*));
253 extern Sfoff_t		sfseek _ARG_((Sfio_t*, Sfoff_t, int));
254 extern ssize_t		sfputr _ARG_((Sfio_t*, const char*, int));
255 extern char*		sfgetr _ARG_((Sfio_t*, int, int));
256 extern ssize_t		sfnputc _ARG_((Sfio_t*, int, size_t));
257 extern int		sfungetc _ARG_((Sfio_t*, int));
258 extern int		sfprintf _ARG_((Sfio_t*, const char*, ...));
259 extern char*		sfprints _ARG_((const char*, ...));
260 extern ssize_t		sfsprintf _ARG_((char*, size_t, const char*, ...));
261 extern ssize_t		sfvsprintf _ARG_((char*, size_t, const char*, va_list));
262 extern int		sfvprintf _ARG_((Sfio_t*, const char*, va_list));
263 extern int		sfscanf _ARG_((Sfio_t*, const char*, ...));
264 extern int		sfsscanf _ARG_((const char*, const char*, ...));
265 extern int		sfvsscanf _ARG_((const char*, const char*, va_list));
266 extern int		sfvscanf _ARG_((Sfio_t*, const char*, va_list));
267 
268 /* mutex locking for thread-safety */
269 extern int		sfmutex _ARG_((Sfio_t*, int));
270 
271 /* io functions with discipline continuation */
272 extern ssize_t		sfrd _ARG_((Sfio_t*, Void_t*, size_t, Sfdisc_t*));
273 extern ssize_t		sfwr _ARG_((Sfio_t*, const Void_t*, size_t, Sfdisc_t*));
274 extern Sfoff_t		sfsk _ARG_((Sfio_t*, Sfoff_t, int, Sfdisc_t*));
275 extern ssize_t		sfpkrd _ARG_((int, Void_t*, size_t, int, long, int));
276 
277 /* portable handling of primitive types */
278 extern int		sfdlen _ARG_((Sfdouble_t));
279 extern int		sfllen _ARG_((Sflong_t));
280 extern int		sfulen _ARG_((Sfulong_t));
281 
282 extern int		sfputd _ARG_((Sfio_t*, Sfdouble_t));
283 extern int		sfputl _ARG_((Sfio_t*, Sflong_t));
284 extern int		sfputu _ARG_((Sfio_t*, Sfulong_t));
285 extern int		sfputm _ARG_((Sfio_t*, Sfulong_t, Sfulong_t));
286 extern int		sfputc _ARG_((Sfio_t*, int));
287 
288 extern Sfdouble_t	sfgetd _ARG_((Sfio_t*));
289 extern Sflong_t		sfgetl _ARG_((Sfio_t*));
290 extern Sfulong_t	sfgetu _ARG_((Sfio_t*));
291 extern Sfulong_t	sfgetm _ARG_((Sfio_t*, Sfulong_t));
292 extern int		sfgetc _ARG_((Sfio_t*));
293 
294 extern int		_sfputd _ARG_((Sfio_t*, Sfdouble_t));
295 extern int		_sfputl _ARG_((Sfio_t*, Sflong_t));
296 extern int		_sfputu _ARG_((Sfio_t*, Sfulong_t));
297 extern int		_sfputm _ARG_((Sfio_t*, Sfulong_t, Sfulong_t));
298 extern int		_sfflsbuf _ARG_((Sfio_t*, int));
299 
300 extern int		_sffilbuf _ARG_((Sfio_t*, int));
301 
302 extern int		_sfdlen _ARG_((Sfdouble_t));
303 extern int		_sfllen _ARG_((Sflong_t));
304 extern int		_sfulen _ARG_((Sfulong_t));
305 
306 /* miscellaneous function analogues of fast in-line functions */
307 extern Sfoff_t		sfsize _ARG_((Sfio_t*));
308 extern int		sfclrerr _ARG_((Sfio_t*));
309 extern int		sfeof _ARG_((Sfio_t*));
310 extern int		sferror _ARG_((Sfio_t*));
311 extern int		sffileno _ARG_((Sfio_t*));
312 extern int		sfstacked _ARG_((Sfio_t*));
313 extern ssize_t		sfvalue _ARG_((Sfio_t*));
314 extern ssize_t		sfslen _ARG_((void));
315 extern ssize_t		sfmaxr _ARG_((ssize_t, int));
316 
317 #undef extern
318 _END_EXTERNS_
319 
320 /* coding long integers in a portable and compact fashion */
321 #define SF_SBITS	6
322 #define SF_UBITS	7
323 #define SF_BBITS	8
324 #define SF_SIGN		(1 << SF_SBITS)
325 #define SF_MORE		(1 << SF_UBITS)
326 #define SF_BYTE		(1 << SF_BBITS)
327 #define SF_U1		SF_MORE
328 #define SF_U2		(SF_U1*SF_U1)
329 #define SF_U3		(SF_U2*SF_U1)
330 #define SF_U4		(SF_U3*SF_U1)
331 
332 #if __cplusplus
333 #define _SF_(f)		(f)
334 #else
335 #define _SF_(f)		((Sfio_t*)(f))
336 #endif
337 
338 #define __sf_putd(f,v)		(_sfputd(_SF_(f),(Sfdouble_t)(v)))
339 #define __sf_putl(f,v)		(_sfputl(_SF_(f),(Sflong_t)(v)))
340 #define __sf_putu(f,v)		(_sfputu(_SF_(f),(Sfulong_t)(v)))
341 #define __sf_putm(f,v,m)	(_sfputm(_SF_(f),(Sfulong_t)(v),(Sfulong_t)(m)))
342 
343 #define __sf_putc(f,c)	(_SF_(f)->_next >= _SF_(f)->_endw ? \
344 			 _sfflsbuf(_SF_(f),(int)((unsigned char)(c))) : \
345 			 (int)(*_SF_(f)->_next++ = (unsigned char)(c)) )
346 #define __sf_getc(f)	(_SF_(f)->_next >= _SF_(f)->_endr ? _sffilbuf(_SF_(f),0) : \
347 			 (int)(*_SF_(f)->_next++) )
348 
349 #define __sf_dlen(v)	(_sfdlen((Sfdouble_t)(v)) )
350 #define __sf_llen(v)	(_sfllen((Sflong_t)(v)) )
351 #define __sf_ulen(v)	((Sfulong_t)(v) < SF_U1 ? 1 : (Sfulong_t)(v) < SF_U2 ? 2 : \
352 			 (Sfulong_t)(v) < SF_U3 ? 3 : (Sfulong_t)(v) < SF_U4 ? 4 : 5)
353 
354 #define __sf_fileno(f)	(_SF_(f)->_file)
355 #define __sf_eof(f)	(_SF_(f)->_flags&SF_EOF)
356 #define __sf_error(f)	(_SF_(f)->_flags&SF_ERROR)
357 #define __sf_clrerr(f)	(_SF_(f)->_flags &= ~(SF_ERROR|SF_EOF))
358 #define __sf_stacked(f)	(_SF_(f)->_push != (Sfio_t*)0)
359 #define __sf_value(f)	(_SF_(f)->_val)
360 #define __sf_slen()	(_Sfi)
361 #define __sf_maxr(n,s)	((s)?((_Sfi=_Sfmaxr),(_Sfmaxr=(n)),_Sfi):_Sfmaxr)
362 
363 #if defined(__INLINE__) && !_BLD_sfio
364 
365 __INLINE__ int sfputd(Sfio_t* f, Sfdouble_t v)	{ return __sf_putd(f,v); }
366 __INLINE__ int sfputl(Sfio_t* f, Sflong_t v)	{ return __sf_putl(f,v); }
367 __INLINE__ int sfputu(Sfio_t* f, Sfulong_t v)	{ return __sf_putu(f,v); }
368 __INLINE__ int sfputm(Sfio_t* f, Sfulong_t v, Sfulong_t m)
369 						{ return __sf_putm(f,v,m); }
370 
371 __INLINE__ int sfputc(Sfio_t* f, int c)		{ return __sf_putc(f,c); }
372 __INLINE__ int sfgetc(Sfio_t* f)		{ return __sf_getc(f); }
373 
374 __INLINE__ int sfdlen(Sfdouble_t v)		{ return __sf_dlen(v); }
375 __INLINE__ int sfllen(Sflong_t v)		{ return __sf_llen(v); }
376 __INLINE__ int sfulen(Sfulong_t v)		{ return __sf_ulen(v); }
377 
378 __INLINE__ int sffileno(Sfio_t* f)		{ return __sf_fileno(f); }
379 __INLINE__ int sfeof(Sfio_t* f)			{ return __sf_eof(f); }
380 __INLINE__ int sferror(Sfio_t* f)		{ return __sf_error(f); }
381 __INLINE__ int sfclrerr(Sfio_t* f)		{ return __sf_clrerr(f); }
382 __INLINE__ int sfstacked(Sfio_t* f)		{ return __sf_stacked(f); }
383 __INLINE__ ssize_t sfvalue(Sfio_t* f)		{ return __sf_value(f); }
384 __INLINE__ ssize_t sfslen()			{ return __sf_slen(); }
385 __INLINE__ ssize_t sfmaxr(ssize_t n, int s)	{ return __sf_maxr(n,s); }
386 
387 #else
388 
389 #define sfputd(f,v)				( __sf_putd((f),(v)) )
390 #define sfputl(f,v)				( __sf_putl((f),(v)) )
391 #define sfputu(f,v)				( __sf_putu((f),(v)) )
392 #define sfputm(f,v,m)				( __sf_putm((f),(v),(m)) )
393 
394 #define sfputc(f,c)				( __sf_putc((f),(c)) )
395 #define sfgetc(f)				( __sf_getc(f) )
396 
397 #define sfdlen(v)				( __sf_dlen(v) )
398 #define sfllen(v)				( __sf_llen(v) )
399 #define sfulen(v)				( __sf_ulen(v) )
400 
401 #define sffileno(f)				( __sf_fileno(f) )
402 #define sfeof(f)				( __sf_eof(f) )
403 #define sferror(f)				( __sf_error(f) )
404 #define sfclrerr(f)				( __sf_clrerr(f) )
405 #define sfstacked(f)				( __sf_stacked(f) )
406 #define sfvalue(f)				( __sf_value(f) )
407 #define sfslen()				( __sf_slen() )
408 #define sfmaxr(n,s)				( __sf_maxr(n,s) )
409 
410 #endif /*__INLINE__*/
411 
412 #ifndef _SFSTR_H /* GSF's string manipulation stuff */
413 #define _SFSTR_H		1
414 
415 #define sfstropen()		sfnew(0, 0, -1, -1, SF_READ|SF_WRITE|SF_STRING)
416 #define sfstrclose(f)		sfclose(f)
417 
418 #define sfstrseek(f,p,m) \
419 	( (m) == SEEK_SET ? \
420 	 	(((p) < 0 || (p) > (f)->_size) ? (char*)0 : \
421 		 (char*)((f)->_next = (f)->_data+(p)) ) \
422 	: (m) == SEEK_CUR ? \
423 		((f)->_next += (p), \
424 		 (((f)->_next < (f)->_data || (f)->_next > (f)->_data+(f)->_size) ? \
425 			((f)->_next -= (p), (char*)0) : (char*)(f)->_next ) ) \
426 	: (m) == SEEK_END ? \
427 		( ((p) > 0 || (f)->_size+(p) < 0) ? (char*)0 : \
428 			(char*)((f)->_next = (f)->_data+(f)->_size+(p)) ) \
429 	: (char*)0 \
430 	)
431 
432 #define sfstrsize(f)		((f)->_size)
433 #define sfstrtell(f)		((f)->_next - (f)->_data)
434 #define sfstrpend(f)		((f)->_size - sfstrtell())
435 #define sfstrbase(f)		((char*)(f)->_data)
436 
437 #define sfstruse(f) \
438 	(sfputc((f),0) < 0 ? (char*)0 : (char*)((f)->_next = (f)->_data) \
439 	)
440 
441 #define sfstrrsrv(f,n) \
442 	(sfreserve((f),(n),SF_WRITE|SF_LOCKR), sfwrite((f),(f)->_next,0), \
443 	 ((f)->_next+(n) <= (f)->_data+(f)->_size ? (char*)(f)->_next : (char*)0) \
444 	)
445 
446 #define sfstrbuf(f,b,n,m) \
447 	(sfsetbuf((f),(b),(n)), ((f)->_flags |= (m) ? SF_MALLOC : 0), \
448 	 ((f)->_data == (unsigned char*)(b) ? 0 : -1) \
449 	)
450 
451 #endif /* _SFSTR_H */
452 
453 #endif /* _SFIO_H */
454