xref: /titanic_41/usr/src/lib/libast/common/sfio/sfextern.c (revision db2bae3047e71d795bde12e3baa621f4b6cc8930)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *           Copyright (c) 1985-2007 AT&T Knowledge Ventures            *
5 *                      and is licensed under the                       *
6 *                  Common Public License, Version 1.0                  *
7 *                      by AT&T Knowledge Ventures                      *
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, int))),		/* _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 #if INT_MAX == LONG_MAX
64 ssize_t _Sfmaxr = 64*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 #else
75 #define SFMTXIN		(0)
76 #define SFMTXOUT	(0)
77 #define SFMTXERR	(0)
78 #endif
79 
80 Sfio_t	_Sfstdin  = SFNEW(NIL(char*),-1,0,
81 			  (SF_READ |SF_STATIC|SF_MTSAFE),NIL(Sfdisc_t*),SFMTXIN);
82 Sfio_t	_Sfstdout = SFNEW(NIL(char*),-1,1,
83 			  (SF_WRITE|SF_STATIC|SF_MTSAFE),NIL(Sfdisc_t*),SFMTXOUT);
84 Sfio_t	_Sfstderr = SFNEW(NIL(char*),-1,2,
85 			  (SF_WRITE|SF_STATIC|SF_MTSAFE),NIL(Sfdisc_t*),SFMTXERR);
86 
87 #undef	sfstdin
88 #undef	sfstdout
89 #undef	sfstderr
90 
91 Sfio_t*	sfstdin  = &_Sfstdin;
92 Sfio_t*	sfstdout = &_Sfstdout;
93 Sfio_t*	sfstderr = &_Sfstderr;
94 
95 __EXTERN__(ssize_t,_Sfi);
96 __EXTERN__(Sfio_t,_Sfstdin);
97 __EXTERN__(Sfio_t,_Sfstdout);
98 __EXTERN__(Sfio_t,_Sfstderr);
99 __EXTERN__(Sfio_t*,sfstdin);
100 __EXTERN__(Sfio_t*,sfstdout);
101 __EXTERN__(Sfio_t*,sfstderr);
102