xref: /titanic_41/usr/src/lib/libast/common/sfio/sfextern.c (revision a026686c807bfa501e774c70b45ef875ed7de130)
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 #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 #ifdef _ast_int8_t
64 ssize_t _Sfmaxr = 256*1024;	/* default maximum size for a record	*/
65 #else
66 ssize_t _Sfmaxr = 16*1024;	/* default maximum size for a record	*/
67 #endif
68 
69 #if vt_threaded
70 static Vtmutex_t	_Sfmtxin, _Sfmtxout, _Sfmtxerr;
71 #define SFMTXIN		(&_Sfmtxin)
72 #define SFMTXOUT	(&_Sfmtxout)
73 #define SFMTXERR	(&_Sfmtxerr)
74 #define SF_STDSAFE	SF_MTSAFE
75 #else
76 #define SFMTXIN		(0)
77 #define SFMTXOUT	(0)
78 #define SFMTXERR	(0)
79 #define SF_STDSAFE	(0)
80 #endif
81 
82 Sfio_t	_Sfstdin  = SFNEW(NIL(char*),-1,0,
83 			  (SF_READ |SF_STATIC|SF_STDSAFE),NIL(Sfdisc_t*),SFMTXIN);
84 Sfio_t	_Sfstdout = SFNEW(NIL(char*),-1,1,
85 			  (SF_WRITE|SF_STATIC|SF_STDSAFE),NIL(Sfdisc_t*),SFMTXOUT);
86 Sfio_t	_Sfstderr = SFNEW(NIL(char*),-1,2,
87 			  (SF_WRITE|SF_STATIC|SF_STDSAFE),NIL(Sfdisc_t*),SFMTXERR);
88 
89 #undef	sfstdin
90 #undef	sfstdout
91 #undef	sfstderr
92 
93 Sfio_t*	sfstdin  = &_Sfstdin;
94 Sfio_t*	sfstdout = &_Sfstdout;
95 Sfio_t*	sfstderr = &_Sfstderr;
96 
97 __EXTERN__(ssize_t,_Sfi);
98 __EXTERN__(Sfio_t,_Sfstdin);
99 __EXTERN__(Sfio_t,_Sfstdout);
100 __EXTERN__(Sfio_t,_Sfstderr);
101 __EXTERN__(Sfio_t*,sfstdin);
102 __EXTERN__(Sfio_t*,sfstdout);
103 __EXTERN__(Sfio_t*,sfstderr);
104