xref: /onnv-gate/usr/src/lib/libast/common/stdio/_stdfun.c (revision 12068:08a39a083754)
14887Schin /***********************************************************************
24887Schin *                                                                      *
34887Schin *               This software is part of the ast package               *
4*12068SRoger.Faulkner@Oracle.COM *          Copyright (c) 1985-2010 AT&T Intellectual Property          *
54887Schin *                      and is licensed under the                       *
64887Schin *                  Common Public License, Version 1.0                  *
78462SApril.Chin@Sun.COM *                    by AT&T Intellectual Property                     *
84887Schin *                                                                      *
94887Schin *                A copy of the License is available at                 *
104887Schin *            http://www.opensource.org/licenses/cpl1.0.txt             *
114887Schin *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
124887Schin *                                                                      *
134887Schin *              Information and Software Systems Research               *
144887Schin *                            AT&T Research                             *
154887Schin *                           Florham Park NJ                            *
164887Schin *                                                                      *
174887Schin *                 Glenn Fowler <gsf@research.att.com>                  *
184887Schin *                  David Korn <dgk@research.att.com>                   *
194887Schin *                   Phong Vo <kpv@research.att.com>                    *
204887Schin *                                                                      *
214887Schin ***********************************************************************/
224887Schin #pragma prototyped
234887Schin 
244887Schin #include <ast.h>
254887Schin 
264887Schin #if !_UWIN
274887Schin 
_STUB_stdfun()284887Schin void _STUB_stdfun(){}
294887Schin 
304887Schin #else
314887Schin 
324887Schin #include <ast_windows.h>
334887Schin #include <uwin.h>
344887Schin #include <dlfcn.h>
354887Schin #include "FEATURE/uwin"
364887Schin 
374887Schin #if _lib___iob_func
384887Schin #define IOB		((char*)__iob_func())
3910898Sroland.mainz@nrubsig.org #elif _lib___p__iob
4010898Sroland.mainz@nrubsig.org #define IOB		((char*)__p__iob())
414887Schin #elif _dat__iob
424887Schin #define IOB		((char*)_iob)
434887Schin #else
4410898Sroland.mainz@nrubsig.org #define IOB		((char*)_p__iob())
454887Schin #endif
464887Schin 
474887Schin #define IOBMAX		(512*32)
484887Schin 
494887Schin #include "stdhdr.h"
504887Schin 
514887Schin int
_stdfun(Sfio_t * f,Funvec_t * vp)524887Schin _stdfun(Sfio_t* f, Funvec_t* vp)
534887Schin {
544887Schin 	static char*	iob;
554887Schin 	static int	init;
564887Schin 	static void*	bp;
574887Schin 	static void*	np;
584887Schin 
594887Schin 	if (!iob && !(iob = IOB))
604887Schin 		return 0;
614887Schin 	if (f && ((char*)f < iob || (char*)f > iob+IOBMAX))
624887Schin 		return 0;
634887Schin 	if (!vp->vec[1])
644887Schin 	{
654887Schin 		if (!init)
664887Schin 		{
674887Schin 			init = 1;
684887Schin 			bp = dlopen("/usr/bin/stdio.dll", 0);
694887Schin 		}
704887Schin 		if (bp && (vp->vec[1] = (Fun_f)dlsym(bp, vp->name)))
714887Schin 			return 1;
724887Schin 		if (!np && !(np = dlopen("/sys/msvcrt.dll", 0)))
734887Schin 			return -1;
744887Schin 		if (!(vp->vec[1] = (Fun_f)dlsym(np, vp->name)))
754887Schin 			return -1;
764887Schin 	}
774887Schin 	return 1;
784887Schin }
794887Schin 
804887Schin #endif
81