From: Gurusamy Sarathy Date: Fri, 3 Dec 1999 06:40:15 +0000 (+0000) Subject: use PerlIO abstraction rather than straight stdio (from X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=33c2a72871842138b67f364dece5097eece0c0df;p=p5sagit%2Fp5-mst-13.2.git use PerlIO abstraction rather than straight stdio (from Chip Salzenberg) p4raw-id: //depot/perl@4629 --- diff --git a/ext/ByteLoader/ByteLoader.xs b/ext/ByteLoader/ByteLoader.xs index c9d7d16..7c3746b 100644 --- a/ext/ByteLoader/ByteLoader.xs +++ b/ext/ByteLoader/ByteLoader.xs @@ -4,12 +4,22 @@ #include "XSUB.h" #include "byterun.h" -#ifdef NEED_FGETC_PROTOTYPE -extern int fgetc(); -#endif -#ifdef NEED_FREAD_PROTOTYPE -extern int fread(); -#endif +static int +xgetc(PerlIO *io) +{ + dTHX; + return PerlIO_getc(io); +} + +static int +xfread(char *buf, size_t size, size_t n, PerlIO *io) +{ + dTHX; + int i = PerlIO_read(io, buf, n * size); + if (i > 0) + i /= size; + return i; +} static void freadpv(U32 len, void *data, XPV *pv) @@ -30,8 +40,8 @@ byteloader_filter(pTHXo_ int idx, SV *buf_sv, int maxlen) struct bytestream bs; bs.data = PL_rsfp; - bs.pfgetc = (int(*) (void*))fgetc; - bs.pfread = (int(*) (char*,size_t,size_t,void*))fread; + bs.pfgetc = (int(*) (void*))xgetc; + bs.pfread = (int(*) (char*,size_t,size_t,void*))xfread; bs.pfreadpv = freadpv; byterun(aTHXo_ bs);