xref: /illumos-gate/usr/src/contrib/ast/src/lib/libast/sfio/sfextern.c (revision 689b9301078f0c35c7f198fcee8032a0d30eff3a)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1985-2011 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 #include	"sfhdr.h"
23 
24 /*	External variables and functions used only by Sfio
25 **	Written by Kiem-Phong Vo
26 */
27 
28 /* code to initialize mutexes */
29 static Vtmutex_t	Sfmutex;
30 static Vtonce_t		Sfonce = VTONCE_INITDATA;
31 static void _sfoncef()
32 {	(void)vtmtxopen(_Sfmutex, VT_INIT);
33 	(void)vtmtxopen(&_Sfpool.mutex, VT_INIT);
34 	(void)vtmtxopen(sfstdin->mutex, VT_INIT);
35 	(void)vtmtxopen(sfstdout->mutex, VT_INIT);
36 	(void)vtmtxopen(sfstderr->mutex, VT_INIT);
37 	_Sfdone = 1;
38 }
39 
40 /* global variables used internally to the package */
41 Sfextern_t _Sfextern =
42 {	0,						/* _Sfpage	*/
43 	{ NIL(Sfpool_t*), 0, 0, 0, NIL(Sfio_t**) },	/* _Sfpool	*/
44 	NIL(int(*)_ARG_((Sfio_t*,int))),		/* _Sfpmove	*/
45 	NIL(Sfio_t*(*)_ARG_((Sfio_t*, Sfio_t*))),	/* _Sfstack	*/
46 	NIL(void(*)_ARG_((Sfio_t*, int, void*))),	/* _Sfnotify	*/
47 	NIL(int(*)_ARG_((Sfio_t*))),			/* _Sfstdsync	*/
48 	{ NIL(Sfread_f),				/* _Sfudisc	*/
49 	  NIL(Sfwrite_f),
50 	  NIL(Sfseek_f),
51 	  NIL(Sfexcept_f),
52 	  NIL(Sfdisc_t*)
53 	},
54 	NIL(void(*)_ARG_((void)) ),			/* _Sfcleanup	*/
55 	0,						/* _Sfexiting	*/
56 	0,						/* _Sfdone	*/
57 	&Sfonce,					/* _Sfonce	*/
58 	_sfoncef,					/* _Sfoncef	*/
59 	&Sfmutex					/* _Sfmutex	*/
60 };
61 
62 ssize_t	_Sfi = -1;		/* value for a few fast macro functions	*/
63 ssize_t _Sfmaxr = 0;		/* default (unlimited) max record size	*/
64 
65 #if vt_threaded
66 static Vtmutex_t	_Sfmtxin, _Sfmtxout, _Sfmtxerr;
67 #define SFMTXIN		(&_Sfmtxin)
68 #define SFMTXOUT	(&_Sfmtxout)
69 #define SFMTXERR	(&_Sfmtxerr)
70 #define SF_STDSAFE	SF_MTSAFE
71 #else
72 #define SFMTXIN		(0)
73 #define SFMTXOUT	(0)
74 #define SFMTXERR	(0)
75 #define SF_STDSAFE	(0)
76 #endif
77 
78 Sfio_t	_Sfstdin  = SFNEW(NIL(char*),-1,0,
79 			  (SF_READ |SF_STATIC|SF_STDSAFE),NIL(Sfdisc_t*),SFMTXIN);
80 Sfio_t	_Sfstdout = SFNEW(NIL(char*),-1,1,
81 			  (SF_WRITE|SF_STATIC|SF_STDSAFE),NIL(Sfdisc_t*),SFMTXOUT);
82 Sfio_t	_Sfstderr = SFNEW(NIL(char*),-1,2,
83 			  (SF_WRITE|SF_STATIC|SF_STDSAFE),NIL(Sfdisc_t*),SFMTXERR);
84 
85 #undef	sfstdin
86 #undef	sfstdout
87 #undef	sfstderr
88 
89 Sfio_t*	sfstdin  = &_Sfstdin;
90 Sfio_t*	sfstdout = &_Sfstdout;
91 Sfio_t*	sfstderr = &_Sfstderr;
92 
93 __EXTERN__(ssize_t,_Sfi);
94 __EXTERN__(Sfio_t,_Sfstdin);
95 __EXTERN__(Sfio_t,_Sfstdout);
96 __EXTERN__(Sfio_t,_Sfstderr);
97 __EXTERN__(Sfio_t*,sfstdin);
98 __EXTERN__(Sfio_t*,sfstdout);
99 __EXTERN__(Sfio_t*,sfstderr);
100