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 #include "sfdchdr.h"
234887Schin
244887Schin /* Make a stream op return immediately on interrupts.
254887Schin ** This is useful on slow streams (hence the name).
264887Schin **
274887Schin ** Written by Glenn Fowler (03/18/1998).
284887Schin */
294887Schin
304887Schin #if __STD_C
slowexcept(Sfio_t * f,int type,Void_t * v,Sfdisc_t * disc)314887Schin static int slowexcept(Sfio_t* f, int type, Void_t* v, Sfdisc_t* disc)
324887Schin #else
334887Schin static int slowexcept(f, type, v, disc)
344887Schin Sfio_t* f;
354887Schin int type;
364887Schin Void_t* v;
374887Schin Sfdisc_t* disc;
384887Schin #endif
394887Schin {
404887Schin NOTUSED(f);
414887Schin NOTUSED(v);
424887Schin NOTUSED(disc);
434887Schin
444887Schin switch (type)
454887Schin {
464887Schin case SF_FINAL:
474887Schin case SF_DPOP:
484887Schin free(disc);
494887Schin break;
504887Schin case SF_READ:
514887Schin case SF_WRITE:
524887Schin if (errno == EINTR)
534887Schin return(-1);
544887Schin break;
554887Schin }
564887Schin
574887Schin return(0);
584887Schin }
594887Schin
604887Schin #if __STD_C
sfdcslow(Sfio_t * f)614887Schin int sfdcslow(Sfio_t* f)
624887Schin #else
634887Schin int sfdcslow(f)
644887Schin Sfio_t* f;
654887Schin #endif
664887Schin {
674887Schin Sfdisc_t* disc;
684887Schin
694887Schin if(!(disc = (Sfdisc_t*)malloc(sizeof(Sfdisc_t))) )
704887Schin return(-1);
714887Schin
724887Schin disc->readf = NIL(Sfread_f);
734887Schin disc->writef = NIL(Sfwrite_f);
744887Schin disc->seekf = NIL(Sfseek_f);
754887Schin disc->exceptf = slowexcept;
764887Schin
774887Schin if(sfdisc(f,disc) != disc)
784887Schin { free(disc);
794887Schin return(-1);
804887Schin }
814887Schin
824887Schin return(0);
834887Schin }
84