return -1;
}
+void
+PerlIO_destruct(pTHX)
+{
+}
+
int
PerlIO_binmode(pTHX_ PerlIO *fp, int iotype, int mode, const char *names)
{
{
if (narg == 1)
{
- char *name = SvPV_nolen(*args);
- if (*mode == '#')
- {
- fd = PerlLIO_open3(name,imode,perm);
- if (fd >= 0)
- return PerlIO_fdopen(fd,mode+1);
- }
- else if (old)
- {
- return PerlIO_reopen(name,mode,old);
- }
+ if (*args == &PL_sv_undef)
+ return PerlIO_tmpfile();
else
{
- return PerlIO_open(name,mode);
+ char *name = SvPV_nolen(*args);
+ if (*mode == '#')
+ {
+ fd = PerlLIO_open3(name,imode,perm);
+ if (fd >= 0)
+ return PerlIO_fdopen(fd,mode+1);
+ }
+ else if (old)
+ {
+ return PerlIO_reopen(name,mode,old);
+ }
+ else
+ {
+ return PerlIO_open(name,mode);
+ }
}
}
else
PerlIO *_perlio = NULL;
#define PERLIO_TABLE_SIZE 64
+
+
PerlIO *
PerlIO_allocate(pTHX)
{
}
void
+PerlIO_destruct(pTHX)
+{
+ PerlIO **table = &_perlio;
+ PerlIO *f;
+ while ((f = *table))
+ {
+ int i;
+ table = (PerlIO **)(f++);
+ for (i=1; i < PERLIO_TABLE_SIZE; i++)
+ {
+ PerlIO *x = f;
+ PerlIOl *l;
+ while ((l = *x))
+ {
+ if (l->tab->kind & PERLIO_K_DESTRUCT)
+ {
+ PerlIO_debug("Destruct popping %s\n",l->tab->name);
+ PerlIO_flush(x);
+ PerlIO_pop(aTHX_ x);
+ }
+ else
+ {
+ x = PerlIONext(x);
+ }
+ }
+ f++;
+ }
+ }
+}
+
+void
PerlIO_pop(pTHX_ PerlIO *f)
{
PerlIOl *l = *f;
/*--------------------------------------------------------------------------------------*/
/* XS Interface for perl code */
-XS(XS_perlio_import)
-{
- dXSARGS;
- GV *gv = CvGV(cv);
- char *s = GvNAME(gv);
- STRLEN l = GvNAMELEN(gv);
- PerlIO_debug("%.*s\n",(int) l,s);
- XSRETURN_EMPTY;
-}
-
-XS(XS_perlio_unimport)
-{
- dXSARGS;
- GV *gv = CvGV(cv);
- char *s = GvNAME(gv);
- STRLEN l = GvNAMELEN(gv);
- PerlIO_debug("%.*s\n",(int) l,s);
- XSRETURN_EMPTY;
-}
-
SV *
-PerlIO_find_layer(pTHX_ const char *name, STRLEN len)
+PerlIO_find_layer(pTHX_ const char *name, STRLEN len, int load)
{
SV **svp;
SV *sv;
if ((SSize_t) len <= 0)
len = strlen(name);
svp = hv_fetch(PerlIO_layer_hv,name,len,0);
- if (svp && (sv = *svp) && SvROK(sv))
- return *svp;
- return NULL;
+ if (!svp && load && PL_subname && PerlIO_layer_av && av_len(PerlIO_layer_av)+1 >= 2)
+ {
+ SV *pkgsv = newSVpvn("PerlIO",6);
+ SV *layer = newSVpvn(name,len);
+ ENTER;
+ /* The two SVs are magically freed by load_module */
+ Perl_load_module(aTHX_ 0, pkgsv, Nullsv, layer, Nullsv);
+ LEAVE;
+ /* Say this is lvalue so we get an 'undef' if still not there */
+ svp = hv_fetch(PerlIO_layer_hv,name,len,1);
+ }
+ if (svp && (sv = *svp))
+ {
+ if (SvROK(sv))
+ return *svp;
+ }
+ return Nullsv;
}
{
STRLEN len;
const char *name = SvPV(ST(i),len);
- SV *layer = PerlIO_find_layer(aTHX_ name,len);
+ SV *layer = PerlIO_find_layer(aTHX_ name,len,1);
if (layer)
{
av_push(av,SvREFCNT_inc(layer));
XSRETURN(count);
}
+SV *
+PerlIO_tab_sv(pTHX_ PerlIO_funcs *tab)
+{
+ HV *stash = gv_stashpv("PerlIO::Layer", TRUE);
+ SV *sv = sv_bless(newRV_noinc(newSViv(PTR2IV(tab))),stash);
+ return sv;
+}
+
void
PerlIO_define_layer(pTHX_ PerlIO_funcs *tab)
{
- HV *stash = gv_stashpv("perlio::Layer", TRUE);
- SV *sv = sv_bless(newRV_noinc(newSViv(PTR2IV(tab))),stash);
if (!PerlIO_layer_hv)
{
PerlIO_layer_hv = get_hv("open::layers",GV_ADD|GV_ADDMULTI);
}
- hv_store(PerlIO_layer_hv,tab->name,strlen(tab->name),sv,0);
+ hv_store(PerlIO_layer_hv,tab->name,strlen(tab->name),PerlIO_tab_sv(aTHX_ tab),0);
PerlIO_debug("define %s %p\n",tab->name,tab);
}
+int
+PerlIO_parse_layers(pTHX_ AV *av, const char *names)
+{
+ if (names)
+ {
+ const char *s = names;
+ while (*s)
+ {
+ while (isSPACE(*s) || *s == ':')
+ s++;
+ if (*s)
+ {
+ STRLEN llen = 0;
+ const char *e = s;
+ const char *as = Nullch;
+ STRLEN alen = 0;
+ if (!isIDFIRST(*s))
+ {
+ /* Message is consistent with how attribute lists are passed.
+ Even though this means "foo : : bar" is seen as an invalid separator
+ character. */
+ char q = ((*s == '\'') ? '"' : '\'');
+ Perl_warn(aTHX_ "perlio: invalid separator character %c%c%c in layer specification list", q, *s, q);
+ return -1;
+ }
+ do
+ {
+ e++;
+ } while (isALNUM(*e));
+ llen = e-s;
+ if (*e == '(')
+ {
+ int nesting = 1;
+ as = ++e;
+ while (nesting)
+ {
+ switch (*e++)
+ {
+ case ')':
+ if (--nesting == 0)
+ alen = (e-1)-as;
+ break;
+ case '(':
+ ++nesting;
+ break;
+ case '\\':
+ /* It's a nul terminated string, not allowed to \ the terminating null.
+ Anything other character is passed over. */
+ if (*e++)
+ {
+ break;
+ }
+ /* Drop through */
+ case '\0':
+ e--;
+ Perl_warn(aTHX_ "perlio: argument list not closed for layer \"%.*s\"",(int)(e - s),s);
+ return -1;
+ default:
+ /* boring. */
+ break;
+ }
+ }
+ }
+ if (e > s)
+ {
+ SV *layer = PerlIO_find_layer(aTHX_ s,llen,1);
+ if (layer)
+ {
+ av_push(av,SvREFCNT_inc(layer));
+ av_push(av,(as) ? newSVpvn(as,alen) : &PL_sv_undef);
+ }
+ else {
+ Perl_warn(aTHX_ "perlio: unknown layer \"%.*s\"",(int)llen,s);
+ return -1;
+ }
+ }
+ s = e;
+ }
+ }
+ }
+ return 0;
+}
+
void
-PerlIO_default_buffer(pTHX)
+PerlIO_default_buffer(pTHX_ AV *av)
{
PerlIO_funcs *tab = &PerlIO_perlio;
if (O_BINARY != O_TEXT)
}
}
PerlIO_debug("Pushing %s\n",tab->name);
- av_push(PerlIO_layer_av,SvREFCNT_inc(PerlIO_find_layer(aTHX_ tab->name,0)));
+ av_push(av,SvREFCNT_inc(PerlIO_find_layer(aTHX_ tab->name,0,0)));
+ av_push(av,&PL_sv_undef);
}
-
+SV *
+PerlIO_arg_fetch(pTHX_ AV *av,IV n)
+{
+ SV **svp = av_fetch(av,n,FALSE);
+ return (svp) ? *svp : Nullsv;
+}
PerlIO_funcs *
-PerlIO_default_layer(pTHX_ I32 n)
+PerlIO_layer_fetch(pTHX_ AV *av,IV n,PerlIO_funcs *def)
{
- SV **svp;
+ SV **svp = av_fetch(av,n,FALSE);
SV *layer;
- PerlIO_funcs *tab = &PerlIO_stdio;
- int len;
+ if (svp && (layer = *svp) && SvROK(layer) && SvIOK((layer = SvRV(layer))))
+ {
+ /* PerlIO_debug("Layer %d is %s\n",n/2,tab->name); */
+ return INT2PTR(PerlIO_funcs *, SvIV(layer));
+ }
+ if (!def)
+ Perl_croak(aTHX_ "panic:PerlIO layer array corrupt");
+ return def;
+}
+
+AV *
+PerlIO_default_layers(pTHX)
+{
+ IV len;
if (!PerlIO_layer_av)
{
- const char *s = PerlEnv_getenv("PERLIO");
+ const char *s = (PL_tainting) ? Nullch : PerlEnv_getenv("PERLIO");
PerlIO_layer_av = get_av("open::layers",GV_ADD|GV_ADDMULTI);
- newXS("perlio::import",XS_perlio_import,__FILE__);
- newXS("perlio::unimport",XS_perlio_unimport,__FILE__);
#if 0
newXS("io::MODIFY_SCALAR_ATTRIBUTES",XS_io_MODIFY_SCALAR_ATTRIBUTES,__FILE__);
#endif
#endif
PerlIO_define_layer(aTHX_ &PerlIO_utf8);
PerlIO_define_layer(aTHX_ &PerlIO_byte);
- av_push(PerlIO_layer_av,SvREFCNT_inc(PerlIO_find_layer(aTHX_ PerlIO_unix.name,0)));
+ av_push(PerlIO_layer_av,SvREFCNT_inc(PerlIO_find_layer(aTHX_ PerlIO_unix.name,0,0)));
+ av_push(PerlIO_layer_av,&PL_sv_undef);
if (s)
{
- IV buffered = 0;
- while (*s)
- {
- while (*s && isSPACE((unsigned char)*s))
- s++;
- if (*s)
- {
- const char *e = s;
- SV *layer;
- while (*e && !isSPACE((unsigned char)*e))
- e++;
- if (*s == ':')
- s++;
- layer = PerlIO_find_layer(aTHX_ s,e-s);
- if (layer)
- {
- PerlIO_funcs *tab = INT2PTR(PerlIO_funcs *, SvIV(SvRV(layer)));
- if ((tab->kind & PERLIO_K_DUMMY) && (tab->kind & PERLIO_K_BUFFERED))
- {
- if (!buffered)
- PerlIO_default_buffer(aTHX);
- }
- PerlIO_debug("Pushing %.*s\n",(e-s),s);
- av_push(PerlIO_layer_av,SvREFCNT_inc(layer));
- buffered |= (tab->kind & PERLIO_K_BUFFERED);
- }
- else
- Perl_warn(aTHX_ "perlio: unknown layer \"%.*s\"",(e-s),s);
- s = e;
- }
- }
+ PerlIO_parse_layers(aTHX_ PerlIO_layer_av,s);
+ }
+ else
+ {
+ PerlIO_default_buffer(aTHX_ PerlIO_layer_av);
}
}
- len = av_len(PerlIO_layer_av);
- if (len < 1)
+ len = av_len(PerlIO_layer_av)+1;
+ if (len < 2)
{
- PerlIO_default_buffer(aTHX);
+ PerlIO_default_buffer(aTHX_ PerlIO_layer_av);
len = av_len(PerlIO_layer_av);
}
+ return PerlIO_layer_av;
+}
+
+
+PerlIO_funcs *
+PerlIO_default_layer(pTHX_ I32 n)
+{
+ AV *av = PerlIO_default_layers(aTHX);
+ n *= 2;
if (n < 0)
- n += len+1;
- svp = av_fetch(PerlIO_layer_av,n,0);
- if (svp && (layer = *svp) && SvROK(layer) && SvIOK((layer = SvRV(layer))))
- {
- tab = INT2PTR(PerlIO_funcs *, SvIV(layer));
- }
- /* PerlIO_debug("Layer %d is %s\n",n,tab->name); */
- return tab;
+ n += av_len(PerlIO_layer_av)+1;
+ return PerlIO_layer_fetch(aTHX_ av,n, &PerlIO_stdio);
}
#define PerlIO_default_top() PerlIO_default_layer(aTHX_ -1)
#define PerlIO_default_btm() PerlIO_default_layer(aTHX_ 0)
void
-PerlIO_stdstreams()
+PerlIO_stdstreams(pTHX)
{
if (!_perlio)
{
- dTHX;
PerlIO_allocate(aTHX);
PerlIO_fdopen(0,"Ir" PERLIO_STDTEXT);
PerlIO_fdopen(1,"Iw" PERLIO_STDTEXT);
}
PerlIO *
-PerlIO_push(pTHX_ PerlIO *f,PerlIO_funcs *tab,const char *mode,const char *arg,STRLEN len)
+PerlIO_push(pTHX_ PerlIO *f,PerlIO_funcs *tab,const char *mode,SV *arg)
{
PerlIOl *l = NULL;
l = PerlMemShared_calloc(tab->size,sizeof(char));
l->next = *f;
l->tab = tab;
*f = l;
- PerlIO_debug("PerlIO_push f=%p %s %s '%.*s'\n",
- f,tab->name,(mode) ? mode : "(Null)",(int) len,arg);
- if ((*l->tab->Pushed)(f,mode,arg,len) != 0)
+ PerlIO_debug("PerlIO_push f=%p %s %s %p\n",f,tab->name,
+ (mode) ? mode : "(Null)",arg);
+ if ((*l->tab->Pushed)(f,mode,arg) != 0)
{
PerlIO_pop(aTHX_ f);
return NULL;
}
IV
-PerlIOPop_pushed(PerlIO *f, const char *mode, const char *arg, STRLEN len)
+PerlIOPop_pushed(PerlIO *f, const char *mode, SV *arg)
{
dTHX;
PerlIO_pop(aTHX_ f);
}
IV
-PerlIORaw_pushed(PerlIO *f, const char *mode, const char *arg, STRLEN len)
+PerlIORaw_pushed(PerlIO *f, const char *mode, SV *arg)
{
/* Remove the dummy layer */
dTHX;
else
{
/* Nothing bellow - push unix on top then remove it */
- if (PerlIO_push(aTHX_ f,PerlIO_default_btm(),mode,arg,len))
+ if (PerlIO_push(aTHX_ f,PerlIO_default_btm(),mode,arg))
{
PerlIO_pop(aTHX_ PerlIONext(f));
}
}
int
-PerlIO_apply_layers(pTHX_ PerlIO *f, const char *mode, const char *names)
+PerlIO_apply_layera(pTHX_ PerlIO *f, const char *mode, AV *layers, IV n)
{
- if (names)
+ IV max = av_len(layers)+1;
+ int code = 0;
+ while (n < max)
{
- const char *s = names;
- while (*s)
+ PerlIO_funcs *tab = PerlIO_layer_fetch(aTHX_ layers,n,NULL);
+ if (tab)
{
- while (isSPACE(*s) || *s == ':')
- s++;
- if (*s)
+ if (!PerlIO_push(aTHX_ f,tab,mode,PerlIOArg))
{
- STRLEN llen = 0;
- const char *e = s;
- const char *as = Nullch;
- STRLEN alen = 0;
- if (!isIDFIRST(*s))
- {
- /* Message is consistent with how attribute lists are passed.
- Even though this means "foo : : bar" is seen as an invalid separator
- character. */
- char q = ((*s == '\'') ? '"' : '\'');
- Perl_warn(aTHX_ "perlio: invalid separator character %c%c%c in layer specification list", q, *s, q);
- return -1;
- }
- do
- {
- e++;
- } while (isALNUM(*e));
- llen = e-s;
- if (*e == '(')
- {
- int nesting = 1;
- as = ++e;
- while (nesting)
- {
- switch (*e++)
- {
- case ')':
- if (--nesting == 0)
- alen = (e-1)-as;
- break;
- case '(':
- ++nesting;
- break;
- case '\\':
- /* It's a nul terminated string, not allowed to \ the terminating null.
- Anything other character is passed over. */
- if (*e++)
- {
- break;
- }
- /* Drop through */
- case '\0':
- e--;
- Perl_warn(aTHX_ "perlio: argument list not closed for layer \"%.*s\"",(int)(e - s),s);
- return -1;
- default:
- /* boring. */
- break;
- }
- }
- }
- if (e > s)
- {
- SV *layer = PerlIO_find_layer(aTHX_ s,llen);
- if (layer)
- {
- PerlIO_funcs *tab = INT2PTR(PerlIO_funcs *, SvIV(SvRV(layer)));
- if (tab)
- {
- if (!PerlIO_push(aTHX_ f,tab,mode,as,alen))
- return -1;
- }
- }
- else {
- Perl_warn(aTHX_ "perlio: unknown layer \"%.*s\"",(int)llen,s);
- return -1;
- }
- }
- s = e;
+ code = -1;
+ break;
}
}
+ n += 2;
}
- return 0;
+ return code;
}
+int
+PerlIO_apply_layers(pTHX_ PerlIO *f, const char *mode, const char *names)
+{
+ int code = 0;
+ if (names)
+ {
+ AV *layers = newAV();
+ code = PerlIO_parse_layers(aTHX_ layers,names);
+ if (code == 0)
+ {
+ code = PerlIO_apply_layera(aTHX_ f, mode, layers, 0);
+ }
+ SvREFCNT_dec((SV *) layers);
+ }
+ return code;
+}
/*--------------------------------------------------------------------------------------*/
int
PerlIO__close(PerlIO *f)
{
- return (*PerlIOBase(f)->tab->Close)(f);
+ if (f && *f)
+ return (*PerlIOBase(f)->tab->Close)(f);
+ else
+ {
+ SETERRNO(EBADF,SS$_IVCHAN);
+ return -1;
+ }
}
#undef PerlIO_fdupopen
PerlIO *
PerlIO_fdupopen(pTHX_ PerlIO *f)
{
- char buf[8];
- int fd = PerlLIO_dup(PerlIO_fileno(f));
- PerlIO *new = PerlIO_fdopen(fd,PerlIO_modestr(f,buf));
- if (new)
+ if (f && *f)
+ {
+ char buf[8];
+ int fd = PerlLIO_dup(PerlIO_fileno(f));
+ PerlIO *new = PerlIO_fdopen(fd,PerlIO_modestr(f,buf));
+ if (new)
+ {
+ Off_t posn = PerlIO_tell(f);
+ PerlIO_seek(new,posn,SEEK_SET);
+ }
+ return new;
+ }
+ else
{
- Off_t posn = PerlIO_tell(f);
- PerlIO_seek(new,posn,SEEK_SET);
+ SETERRNO(EBADF,SS$_IVCHAN);
+ return NULL;
}
- return new;
}
#undef PerlIO_close
PerlIO_close(PerlIO *f)
{
dTHX;
- int code = (*PerlIOBase(f)->tab->Close)(f);
- while (*f)
+ int code = -1;
+ if (f && *f)
{
- PerlIO_pop(aTHX_ f);
+ code = (*PerlIOBase(f)->tab->Close)(f);
+ while (*f)
+ {
+ PerlIO_pop(aTHX_ f);
+ }
}
return code;
}
int
PerlIO_fileno(PerlIO *f)
{
- return (*PerlIOBase(f)->tab->Fileno)(f);
+ if (f && *f)
+ return (*PerlIOBase(f)->tab->Fileno)(f);
+ else
+ {
+ SETERRNO(EBADF,SS$_IVCHAN);
+ return -1;
+ }
}
-PerlIO_funcs *
-PerlIO_top_layer(pTHX_ const char *layers)
+static const char *
+PerlIO_context_layers(pTHX_ const char *mode)
+{
+ const char *type = NULL;
+ /* Need to supply default layer info from open.pm */
+ if (PL_curcop)
+ {
+ SV *layers = PL_curcop->cop_io;
+ if (layers)
+ {
+ STRLEN len;
+ type = SvPV(layers,len);
+ if (type && mode[0] != 'r')
+ {
+ /* Skip to write part */
+ const char *s = strchr(type,0);
+ if (s && (s-type) < len)
+ {
+ type = s+1;
+ }
+ }
+ }
+ }
+ return type;
+}
+
+static SV *
+PerlIO_layer_from_ref(pTHX_ SV *sv)
{
- /* FIXME !!! */
- return PerlIO_default_top();
+ /* For any scalar type load the handler which is bundled with perl */
+ if (SvTYPE(sv) < SVt_PVAV)
+ return PerlIO_find_layer(aTHX_ "Scalar",6, 1);
+
+ /* For other types allow if layer is known but don't try and load it */
+ switch (SvTYPE(sv))
+ {
+ case SVt_PVAV:
+ return PerlIO_find_layer(aTHX_ "Array",5, 0);
+ case SVt_PVHV:
+ return PerlIO_find_layer(aTHX_ "Hash",4, 0);
+ case SVt_PVCV:
+ return PerlIO_find_layer(aTHX_ "Code",4, 0);
+ case SVt_PVGV:
+ return PerlIO_find_layer(aTHX_ "Glob",4, 0);
+ }
+ return Nullsv;
+}
+
+AV *
+PerlIO_resolve_layers(pTHX_ const char *layers,const char *mode,int narg, SV **args)
+{
+ AV *def = PerlIO_default_layers(aTHX);
+ int incdef = 1;
+ if (!_perlio)
+ PerlIO_stdstreams(aTHX);
+ if (narg)
+ {
+ SV *arg = *args;
+ /* If it is a reference but not an object see if we have a handler for it */
+ if (SvROK(arg) && !sv_isobject(arg))
+ {
+ SV *handler = PerlIO_layer_from_ref(aTHX_ SvRV(arg));
+ if (handler)
+ {
+ def = newAV();
+ av_push(def,SvREFCNT_inc(handler));
+ av_push(def,&PL_sv_undef);
+ incdef = 0;
+ }
+ /* Don't fail if handler cannot be found
+ * :Via(...) etc. may do something sensible
+ * else we will just stringfy and open resulting string.
+ */
+ }
+ }
+ if (!layers)
+ layers = PerlIO_context_layers(aTHX_ mode);
+ if (layers && *layers)
+ {
+ AV *av;
+ if (incdef)
+ {
+ IV n = av_len(def)+1;
+ av = newAV();
+ while (n-- > 0)
+ {
+ SV **svp = av_fetch(def,n,0);
+ av_store(av,n,(svp) ? SvREFCNT_inc(*svp) : &PL_sv_undef);
+ }
+ }
+ else
+ {
+ av = def;
+ }
+ PerlIO_parse_layers(aTHX_ av,layers);
+ return av;
+ }
+ else
+ {
+ if (incdef)
+ SvREFCNT_inc(def);
+ return def;
+ }
}
PerlIO *
PerlIO_openn(pTHX_ const char *layers, const char *mode, int fd, int imode, int perm, PerlIO *f, int narg, SV **args)
{
- PerlIO_funcs *tab = (f && *f) ? PerlIOBase(f)->tab : PerlIO_top_layer(aTHX_ layers);
- if (!_perlio)
- PerlIO_stdstreams();
- PerlIO_debug("openn(%s,'%s','%s',%d,%x,%o,%p,%d,%p)\n",
- tab->name,layers,mode,fd,imode,perm,f,narg,args);
- f = (*tab->Open)(aTHX_ tab,mode,fd,imode,perm,f,narg,args);
- if (f)
+ if (!f && narg == 1 && *args == &PL_sv_undef)
+ {
+ if ((f = PerlIO_tmpfile()))
+ {
+ if (!layers)
+ layers = PerlIO_context_layers(aTHX_ mode);
+ if (layers && *layers)
+ PerlIO_apply_layers(aTHX_ f,mode,layers);
+ }
+ }
+ else
{
- if (layers && *layers)
- PerlIO_apply_layers(aTHX_ f,mode,layers);
+ AV *layera;
+ IV n;
+ PerlIO_funcs *tab;
+ if (f && *f)
+ {
+ /* This is "reopen" - it is not tested as perl does not use it yet */
+ PerlIOl *l = *f;
+ layera = newAV();
+ while (l)
+ {
+ SV *arg = (l->tab->Getarg) ? (*l->tab->Getarg)(&l) : &PL_sv_undef;
+ av_unshift(layera,2);
+ av_store(layera,0,PerlIO_tab_sv(aTHX_ l->tab));
+ av_store(layera,1,arg);
+ l = *PerlIONext(&l);
+ }
+ }
+ else
+ {
+ layera = PerlIO_resolve_layers(aTHX_ layers, mode, narg, args);
+ }
+ n = av_len(layera)-1;
+ while (n >= 0)
+ {
+ PerlIO_funcs *t = PerlIO_layer_fetch(aTHX_ layera,n,NULL);
+ if (t && t->Open)
+ {
+ tab = t;
+ break;
+ }
+ n -= 2;
+ }
+ if (tab)
+ {
+ PerlIO_debug("openn(%s,'%s','%s',%d,%x,%o,%p,%d,%p)\n",
+ tab->name,layers,mode,fd,imode,perm,f,narg,args);
+ f = (*tab->Open)(aTHX_ tab, layera, n, mode,fd,imode,perm,f,narg,args);
+ if (f)
+ {
+ if (n+2 < av_len(layera)+1)
+ {
+ if (PerlIO_apply_layera(aTHX_ f, mode, layera, n+2) != 0)
+ {
+ f = NULL;
+ }
+ }
+ }
+ }
+ SvREFCNT_dec(layera);
}
return f;
}
SSize_t
PerlIO_read(PerlIO *f, void *vbuf, Size_t count)
{
- return (*PerlIOBase(f)->tab->Read)(f,vbuf,count);
+ if (f && *f)
+ return (*PerlIOBase(f)->tab->Read)(f,vbuf,count);
+ else
+ {
+ SETERRNO(EBADF,SS$_IVCHAN);
+ return -1;
+ }
}
#undef PerlIO_unread
SSize_t
PerlIO_unread(PerlIO *f, const void *vbuf, Size_t count)
{
- return (*PerlIOBase(f)->tab->Unread)(f,vbuf,count);
+ if (f && *f)
+ return (*PerlIOBase(f)->tab->Unread)(f,vbuf,count);
+ else
+ {
+ SETERRNO(EBADF,SS$_IVCHAN);
+ return -1;
+ }
}
#undef PerlIO_write
SSize_t
PerlIO_write(PerlIO *f, const void *vbuf, Size_t count)
{
- return (*PerlIOBase(f)->tab->Write)(f,vbuf,count);
+ if (f && *f)
+ return (*PerlIOBase(f)->tab->Write)(f,vbuf,count);
+ else
+ {
+ SETERRNO(EBADF,SS$_IVCHAN);
+ return -1;
+ }
}
#undef PerlIO_seek
int
PerlIO_seek(PerlIO *f, Off_t offset, int whence)
{
- return (*PerlIOBase(f)->tab->Seek)(f,offset,whence);
+ if (f && *f)
+ return (*PerlIOBase(f)->tab->Seek)(f,offset,whence);
+ else
+ {
+ SETERRNO(EBADF,SS$_IVCHAN);
+ return -1;
+ }
}
#undef PerlIO_tell
Off_t
PerlIO_tell(PerlIO *f)
{
- return (*PerlIOBase(f)->tab->Tell)(f);
+ if (f && *f)
+ return (*PerlIOBase(f)->tab->Tell)(f);
+ else
+ {
+ SETERRNO(EBADF,SS$_IVCHAN);
+ return -1;
+ }
}
#undef PerlIO_flush
{
if (f)
{
- PerlIO_funcs *tab = PerlIOBase(f)->tab;
- if (tab && tab->Flush)
+ if (*f)
{
- return (*tab->Flush)(f);
+ PerlIO_funcs *tab = PerlIOBase(f)->tab;
+ if (tab && tab->Flush)
+ {
+ return (*tab->Flush)(f);
+ }
+ else
+ {
+ PerlIO_debug("Cannot flush f=%p :%s\n",f,tab->name);
+ SETERRNO(EBADF,SS$_IVCHAN);
+ return -1;
+ }
}
else
{
- PerlIO_debug("Cannot flush f=%p :%s\n",f,tab->name);
- errno = EINVAL;
+ PerlIO_debug("Cannot flush f=%p\n",f);
+ SETERRNO(EBADF,SS$_IVCHAN);
return -1;
}
}
- else
- {
+ else
+ {
+ /* Is it good API design to do flush-all on NULL,
+ * a potentially errorneous input? Maybe some magical
+ * value (PerlIO* PERLIO_FLUSH_ALL = (PerlIO*)-1;)?
+ * Yes, stdio does similar things on fflush(NULL),
+ * but should we be bound by their design decisions?
+ * --jhi */
PerlIO **table = &_perlio;
int code = 0;
while ((f = *table))
}
}
+void
+PerlIOBase_flush_linebuf()
+{
+ PerlIO **table = &_perlio;
+ PerlIO *f;
+ while ((f = *table))
+ {
+ int i;
+ table = (PerlIO **)(f++);
+ for (i=1; i < PERLIO_TABLE_SIZE; i++)
+ {
+ if (*f && (PerlIOBase(f)->flags & (PERLIO_F_LINEBUF|PERLIO_F_CANWRITE))
+ == (PERLIO_F_LINEBUF|PERLIO_F_CANWRITE))
+ PerlIO_flush(f);
+ f++;
+ }
+ }
+}
+
#undef PerlIO_fill
int
PerlIO_fill(PerlIO *f)
{
- return (*PerlIOBase(f)->tab->Fill)(f);
+ if (f && *f)
+ return (*PerlIOBase(f)->tab->Fill)(f);
+ else
+ {
+ SETERRNO(EBADF,SS$_IVCHAN);
+ return -1;
+ }
}
#undef PerlIO_isutf8
int
PerlIO_isutf8(PerlIO *f)
{
- return (PerlIOBase(f)->flags & PERLIO_F_UTF8) != 0;
+ if (f && *f)
+ return (PerlIOBase(f)->flags & PERLIO_F_UTF8) != 0;
+ else
+ {
+ SETERRNO(EBADF,SS$_IVCHAN);
+ return -1;
+ }
}
#undef PerlIO_eof
int
PerlIO_eof(PerlIO *f)
{
- return (*PerlIOBase(f)->tab->Eof)(f);
+ if (f && *f)
+ return (*PerlIOBase(f)->tab->Eof)(f);
+ else
+ {
+ SETERRNO(EBADF,SS$_IVCHAN);
+ return -1;
+ }
}
#undef PerlIO_error
int
PerlIO_error(PerlIO *f)
{
- return (*PerlIOBase(f)->tab->Error)(f);
+ if (f && *f)
+ return (*PerlIOBase(f)->tab->Error)(f);
+ else
+ {
+ SETERRNO(EBADF,SS$_IVCHAN);
+ return -1;
+ }
}
#undef PerlIO_clearerr
{
if (f && *f)
(*PerlIOBase(f)->tab->Clearerr)(f);
+ else
+ SETERRNO(EBADF,SS$_IVCHAN);
}
#undef PerlIO_setlinebuf
void
PerlIO_setlinebuf(PerlIO *f)
{
- (*PerlIOBase(f)->tab->Setlinebuf)(f);
+ if (f && *f)
+ (*PerlIOBase(f)->tab->Setlinebuf)(f);
+ else
+ SETERRNO(EBADF,SS$_IVCHAN);
}
#undef PerlIO_has_base
int
PerlIO_has_base(PerlIO *f)
{
- if (f && *f)
- {
- return (PerlIOBase(f)->tab->Get_base != NULL);
- }
+ if (f && *f) { return (PerlIOBase(f)->tab->Get_base != NULL); }
return 0;
}
STDCHAR *
PerlIO_get_base(PerlIO *f)
{
- return (*PerlIOBase(f)->tab->Get_base)(f);
+ if (f && *f)
+ return (*PerlIOBase(f)->tab->Get_base)(f);
+ return NULL;
}
#undef PerlIO_get_bufsiz
int
PerlIO_get_bufsiz(PerlIO *f)
{
- return (*PerlIOBase(f)->tab->Get_bufsiz)(f);
+ if (f && *f)
+ return (*PerlIOBase(f)->tab->Get_bufsiz)(f);
+ return 0;
}
#undef PerlIO_get_ptr
/* utf8 and raw dummy layers */
IV
-PerlIOUtf8_pushed(PerlIO *f, const char *mode, const char *arg, STRLEN len)
+PerlIOUtf8_pushed(PerlIO *f, const char *mode, SV *arg)
{
if (PerlIONext(f))
{
return -1;
}
-PerlIO *
-PerlIOUtf8_open(pTHX_ PerlIO_funcs *self, const char *mode, int fd, int imode, int perm, PerlIO *old, int narg, SV **args)
-{
- PerlIO_funcs *tab = PerlIO_default_layer(aTHX_ -2);
- PerlIO *f = (*tab->Open)(aTHX_ tab,mode,fd,imode,perm,old,narg,args);
- if (f)
- {
- PerlIOl *l = PerlIOBase(f);
- if (tab->kind & PERLIO_K_UTF8)
- l->flags |= PERLIO_F_UTF8;
- else
- l->flags &= ~PERLIO_F_UTF8;
- }
- return f;
-}
-
PerlIO_funcs PerlIO_utf8 = {
"utf8",
sizeof(PerlIOl),
PERLIO_K_DUMMY|PERLIO_F_UTF8,
- NULL,
- PerlIOUtf8_open,
PerlIOUtf8_pushed,
NULL,
NULL,
NULL,
NULL,
NULL,
+ NULL,
+ NULL,
+ NULL,
NULL, /* flush */
NULL, /* fill */
NULL,
"bytes",
sizeof(PerlIOl),
PERLIO_K_DUMMY,
- NULL,
- PerlIOUtf8_open,
PerlIOUtf8_pushed,
NULL,
NULL,
NULL,
NULL,
NULL,
+ NULL,
+ NULL,
+ NULL,
NULL, /* flush */
NULL, /* fill */
NULL,
};
PerlIO *
-PerlIORaw_open(pTHX_ PerlIO_funcs *self, const char *mode, int fd, int imode, int perm, PerlIO *old, int narg, SV **args)
+PerlIORaw_open(pTHX_ PerlIO_funcs *self, AV *layers, IV n,const char *mode, int fd, int imode, int perm, PerlIO *old, int narg, SV **args)
{
PerlIO_funcs *tab = PerlIO_default_btm();
- return (*tab->Open)(aTHX_ tab,mode,fd,imode,perm,old,narg,args);
+ return (*tab->Open)(aTHX_ tab,layers,n-2,mode,fd,imode,perm,old,narg,args);
}
PerlIO_funcs PerlIO_raw = {
"raw",
sizeof(PerlIOl),
PERLIO_K_DUMMY,
- NULL,
- PerlIORaw_open,
PerlIORaw_pushed,
PerlIOBase_popped,
+ PerlIORaw_open,
+ NULL,
+ NULL,
NULL,
NULL,
NULL,
}
IV
-PerlIOBase_pushed(PerlIO *f, const char *mode, const char *arg, STRLEN len)
+PerlIOBase_pushed(PerlIO *f, const char *mode, SV *arg)
{
PerlIOl *l = PerlIOBase(f);
const char *omode = mode;
l->flags |= PERLIO_F_FASTGETS;
if (mode)
{
+ if (*mode == '#' || *mode == 'I')
+ mode++;
switch (*mode++)
{
case 'r':
l->flags |= PERLIO_F_TRUNCATE|PERLIO_F_CANWRITE;
break;
default:
- errno = EINVAL;
+ SETERRNO(EINVAL,LIB$_INVARG);
return -1;
}
while (*mode)
l->flags |= PERLIO_F_CRLF;
break;
default:
- errno = EINVAL;
- return -1;
+ SETERRNO(EINVAL,LIB$_INVARG);
+ return -1;
}
}
}
dTHX;
Off_t old = PerlIO_tell(f);
SSize_t done;
- PerlIO_push(aTHX_ f,&PerlIO_pending,"r",Nullch,0);
+ PerlIO_push(aTHX_ f,&PerlIO_pending,"r",Nullsv);
done = PerlIOBuf_unread(f,vbuf,count);
PerlIOSelf(f,PerlIOBuf)->posn = old - done;
return done;
}
+SSize_t
+PerlIOBase_read(PerlIO *f, void *vbuf, Size_t count)
+{
+ STDCHAR *buf = (STDCHAR *) vbuf;
+ if (f)
+ {
+ if (!(PerlIOBase(f)->flags & PERLIO_F_CANREAD))
+ return 0;
+ while (count > 0)
+ {
+ SSize_t avail = PerlIO_get_cnt(f);
+ SSize_t take = (count < avail) ? count : avail;
+ if (take > 0)
+ {
+ STDCHAR *ptr = PerlIO_get_ptr(f);
+ Copy(ptr,buf,take,STDCHAR);
+ PerlIO_set_ptrcnt(f,ptr+take,(avail -= take));
+ count -= take;
+ buf += take;
+ }
+ if (count > 0 && avail <= 0)
+ {
+ if (PerlIO_fill(f) != 0)
+ break;
+ }
+ }
+ return (buf - (STDCHAR *) vbuf);
+ }
+ return 0;
+}
+
IV
PerlIOBase_noop_ok(PerlIO *f)
{
PerlIO *n = PerlIONext(f);
if (PerlIO_flush(f) != 0)
code = -1;
- if (n && (*PerlIOBase(n)->tab->Close)(n) != 0)
+ if (n && *n && (*PerlIOBase(n)->tab->Close)(n) != 0)
code = -1;
PerlIOBase(f)->flags &= ~(PERLIO_F_CANREAD|PERLIO_F_CANWRITE|PERLIO_F_OPEN);
return code;
void
PerlIOBase_setlinebuf(PerlIO *f)
{
-
+ if (f)
+ {
+ PerlIOBase(f)->flags |= PERLIO_F_LINEBUF;
+ }
}
/*--------------------------------------------------------------------------------------*/
oflags |= O_BINARY;
if (*mode || oflags == -1)
{
- errno = EINVAL;
+ SETERRNO(EINVAL,LIB$_INVARG);
oflags = -1;
}
return oflags;
}
IV
-PerlIOUnix_pushed(PerlIO *f, const char *mode, const char *arg, STRLEN len)
+PerlIOUnix_pushed(PerlIO *f, const char *mode, SV *arg)
{
- IV code = PerlIOBase_pushed(f,mode,arg,len);
+ IV code = PerlIOBase_pushed(f,mode,arg);
if (*PerlIONext(f))
{
PerlIOUnix *s = PerlIOSelf(f,PerlIOUnix);
}
PerlIO *
-PerlIOUnix_fdopen(PerlIO_funcs *self, int fd,const char *mode)
-{
- dTHX;
- PerlIO *f = NULL;
- if (*mode == 'I')
- mode++;
- if (fd >= 0)
- {
- int oflags = PerlIOUnix_oflags(mode);
- if (oflags != -1)
- {
- PerlIOUnix *s = PerlIOSelf(PerlIO_push(aTHX_ (f = PerlIO_allocate(aTHX)),self,mode,Nullch,0),PerlIOUnix);
- s->fd = fd;
- s->oflags = oflags;
- }
- }
- return f;
-}
-
-PerlIO *
-PerlIOUnix_open(pTHX_ PerlIO_funcs *self, const char *mode, int fd, int imode, int perm, PerlIO *f, int narg, SV **args)
+PerlIOUnix_open(pTHX_ PerlIO_funcs *self, AV *layers, IV n, const char *mode, int fd, int imode, int perm, PerlIO *f, int narg, SV **args)
{
if (f)
{
if (!f)
{
f = PerlIO_allocate(aTHX);
- s = PerlIOSelf(PerlIO_push(aTHX_ f,self,mode,Nullch,0),PerlIOUnix);
+ s = PerlIOSelf(PerlIO_push(aTHX_ f,self,mode,PerlIOArg),PerlIOUnix);
}
else
s = PerlIOSelf(f,PerlIOUnix);
"unix",
sizeof(PerlIOUnix),
PERLIO_K_RAW,
- PerlIOUnix_fileno,
- PerlIOUnix_open,
PerlIOUnix_pushed,
PerlIOBase_noop_ok,
+ PerlIOUnix_open,
+ NULL,
+ PerlIOUnix_fileno,
PerlIOUnix_read,
PerlIOBase_unread,
PerlIOUnix_write,
return ret;
}
-PerlIO *
-PerlIOStdio_fdopen(PerlIO_funcs *self, int fd,const char *mode)
-{
- dTHX;
- PerlIO *f = NULL;
- int init = 0;
- char tmode[8];
-}
-
/* This isn't used yet ... */
IV
-PerlIOStdio_pushed(PerlIO *f, const char *mode, const char *arg, STRLEN len)
+PerlIOStdio_pushed(PerlIO *f, const char *mode, SV *arg)
{
dTHX;
if (*PerlIONext(f))
else
return -1;
}
- return PerlIOBase_pushed(f,mode,arg,len);
+ return PerlIOBase_pushed(f,mode,arg);
}
#undef PerlIO_importFILE
PerlIO *f = NULL;
if (stdio)
{
- PerlIOStdio *s = PerlIOSelf(PerlIO_push(aTHX_ (f = PerlIO_allocate(aTHX)),&PerlIO_stdio,"r+",Nullch,0),PerlIOStdio);
+ PerlIOStdio *s = PerlIOSelf(PerlIO_push(aTHX_ (f = PerlIO_allocate(aTHX)),&PerlIO_stdio,"r+",Nullsv),PerlIOStdio);
s->stdio = stdio;
}
return f;
}
PerlIO *
-PerlIOStdio_open(pTHX_ PerlIO_funcs *self, const char *mode, int fd, int imode, int perm, PerlIO *f, int narg, SV **args)
+PerlIOStdio_open(pTHX_ PerlIO_funcs *self, AV *layers, IV n, const char *mode, int fd, int imode, int perm, PerlIO *f, int narg, SV **args)
{
char tmode[8];
if (f)
if (stdio)
{
PerlIOStdio *s = PerlIOSelf(PerlIO_push(aTHX_ (f = PerlIO_allocate(aTHX)), self,
- (mode = PerlIOStdio_mode(mode,tmode)),Nullch,0),
+ (mode = PerlIOStdio_mode(mode,tmode)),PerlIOArg),
PerlIOStdio);
s->stdio = stdio;
}
}
if (stdio)
{
- PerlIOStdio *s = PerlIOSelf(PerlIO_push(aTHX_ (f = PerlIO_allocate(aTHX)),self,mode,Nullch,0),PerlIOStdio);
+ PerlIOStdio *s = PerlIOSelf(PerlIO_push(aTHX_ (f = PerlIO_allocate(aTHX)),self,mode,PerlIOArg),PerlIOStdio);
s->stdio = stdio;
return f;
}
{
dTHX;
#ifdef HAS_SOCKS5_INIT
- int optval, optlen = sizeof(int);
+ int optval;
+ Sock_size_t optlen = sizeof(int);
#endif
FILE *stdio = PerlIOSelf(f,PerlIOStdio)->stdio;
return(
#ifdef HAS_SOCKS5_INIT
- (getsockopt(PerlIO_fileno(f), SOL_SOCKET, SO_TYPE, (char *)&optval, &optlen) < 0) ?
+ (getsockopt(PerlIO_fileno(f), SOL_SOCKET, SO_TYPE, (void *)&optval, &optlen) < 0) ?
PerlSIO_fclose(stdio) :
close(PerlIO_fileno(f))
#else
"stdio",
sizeof(PerlIOStdio),
PERLIO_K_BUFFERED,
- PerlIOStdio_fileno,
- PerlIOStdio_open,
PerlIOBase_pushed,
PerlIOBase_noop_ok,
+ PerlIOStdio_open,
+ NULL,
+ PerlIOStdio_fileno,
PerlIOStdio_read,
PerlIOStdio_unread,
PerlIOStdio_write,
if (stdio)
{
dTHX;
- PerlIOStdio *s = PerlIOSelf(PerlIO_push(aTHX_ f,&PerlIO_stdio,"r+",Nullch,0),PerlIOStdio);
+ PerlIOStdio *s = PerlIOSelf(PerlIO_push(aTHX_ f,&PerlIO_stdio,"r+",Nullsv),PerlIOStdio);
s->stdio = stdio;
}
return stdio;
/* perlio buffer layer */
IV
-PerlIOBuf_pushed(PerlIO *f, const char *mode, const char *arg, STRLEN len)
+PerlIOBuf_pushed(PerlIO *f, const char *mode, SV *arg)
{
PerlIOBuf *b = PerlIOSelf(f,PerlIOBuf);
int fd = PerlIO_fileno(f);
Off_t posn;
+ dTHX;
if (fd >= 0 && PerlLIO_isatty(fd))
{
- PerlIOBase(f)->flags |= PERLIO_F_LINEBUF;
+ PerlIOBase(f)->flags |= PERLIO_F_LINEBUF|PERLIO_F_TTY;
}
posn = PerlIO_tell(PerlIONext(f));
if (posn != (Off_t) -1)
{
b->posn = posn;
}
- return PerlIOBase_pushed(f,mode,arg,len);
+ return PerlIOBase_pushed(f,mode,arg);
}
PerlIO *
-PerlIOBuf_open(pTHX_ PerlIO_funcs *self, const char *mode, int fd, int imode, int perm, PerlIO *f, int narg, SV **args)
+PerlIOBuf_open(pTHX_ PerlIO_funcs *self, AV *layers, IV n, const char *mode, int fd, int imode, int perm, PerlIO *f, int narg, SV **args)
{
if (f)
{
PerlIO *next = PerlIONext(f);
- PerlIO_funcs *tab = PerlIOBase(next)->tab;
- next = (*tab->Open)(aTHX_ tab,mode,fd,imode,perm,next,narg,args);
- if (!next || (*PerlIOBase(f)->tab->Pushed)(f,mode,Nullch,0) != 0)
+ PerlIO_funcs *tab = PerlIO_layer_fetch(aTHX_ layers, n-2, PerlIOBase(next)->tab);
+ next = (*tab->Open)(aTHX_ tab, layers, n-2, mode,fd,imode,perm,next,narg,args);
+ if (!next || (*PerlIOBase(f)->tab->Pushed)(f,mode,PerlIOArg) != 0)
{
return NULL;
}
}
else
{
- PerlIO_funcs *tab = PerlIO_default_btm();
+ PerlIO_funcs *tab = PerlIO_layer_fetch(aTHX_ layers, n-2, PerlIO_default_btm());
int init = 0;
if (*mode == 'I')
{
init = 1;
mode++;
}
- f = (*tab->Open)(aTHX_ tab,mode,fd,imode,perm,NULL,narg,args);
+ f = (*tab->Open)(aTHX_ tab, layers, n-2, mode,fd,imode,perm,NULL,narg,args);
if (f)
{
- PerlIOBuf *b = PerlIOSelf(PerlIO_push(aTHX_ f,self,mode,Nullch,0),PerlIOBuf);
+ PerlIOBuf *b = PerlIOSelf(PerlIO_push(aTHX_ f,self,mode,PerlIOArg),PerlIOBuf);
fd = PerlIO_fileno(f);
#if O_BINARY != O_TEXT
/* do something about failing setmode()? --jhi */
*/
if (PerlIO_flush(f) != 0)
return -1;
+ if (PerlIOBase(f)->flags & PERLIO_F_TTY)
+ PerlIOBase_flush_linebuf();
if (!b->buf)
PerlIO_get_base(f); /* allocate via vtable */
PerlIOBuf_read(PerlIO *f, void *vbuf, Size_t count)
{
PerlIOBuf *b = PerlIOSelf(f,PerlIOBuf);
- STDCHAR *buf = (STDCHAR *) vbuf;
if (f)
{
if (!b->ptr)
PerlIO_get_base(f);
- if (!(PerlIOBase(f)->flags & PERLIO_F_CANREAD))
- return 0;
- while (count > 0)
- {
- SSize_t avail = PerlIO_get_cnt(f);
- SSize_t take = (count < avail) ? count : avail;
- if (take > 0)
- {
- STDCHAR *ptr = PerlIO_get_ptr(f);
- Copy(ptr,buf,take,STDCHAR);
- PerlIO_set_ptrcnt(f,ptr+take,(avail -= take));
- count -= take;
- buf += take;
- }
- if (count > 0 && avail <= 0)
- {
- if (PerlIO_fill(f) != 0)
- break;
- }
- }
- return (buf - (STDCHAR *) vbuf);
+ return PerlIOBase_read(f,vbuf,count);
}
return 0;
}
return code;
}
-void
-PerlIOBuf_setlinebuf(PerlIO *f)
-{
- if (f)
- {
- PerlIOBase(f)->flags &= ~PERLIO_F_LINEBUF;
- }
-}
-
STDCHAR *
PerlIOBuf_get_ptr(PerlIO *f)
{
"perlio",
sizeof(PerlIOBuf),
PERLIO_K_BUFFERED,
- PerlIOBase_fileno,
- PerlIOBuf_open,
PerlIOBuf_pushed,
PerlIOBase_noop_ok,
+ PerlIOBuf_open,
+ NULL,
+ PerlIOBase_fileno,
PerlIOBuf_read,
PerlIOBuf_unread,
PerlIOBuf_write,
PerlIOBase_eof,
PerlIOBase_error,
PerlIOBase_clearerr,
- PerlIOBuf_setlinebuf,
+ PerlIOBase_setlinebuf,
PerlIOBuf_get_base,
PerlIOBuf_bufsiz,
PerlIOBuf_get_ptr,
}
IV
-PerlIOPending_pushed(PerlIO *f,const char *mode,const char *arg,STRLEN len)
+PerlIOPending_pushed(PerlIO *f,const char *mode,SV *arg)
{
- IV code = PerlIOBase_pushed(f,mode,arg,len);
+ IV code = PerlIOBase_pushed(f,mode,arg);
PerlIOl *l = PerlIOBase(f);
/* Our PerlIO_fast_gets must match what we are pushed on,
or sv_gets() etc. get muddled when it changes mid-string
return got;
}
-
PerlIO_funcs PerlIO_pending = {
"pending",
sizeof(PerlIOBuf),
PERLIO_K_BUFFERED,
- PerlIOBase_fileno,
- NULL,
PerlIOPending_pushed,
PerlIOBase_noop_ok,
+ NULL,
+ NULL,
+ PerlIOBase_fileno,
PerlIOPending_read,
PerlIOBuf_unread,
PerlIOBuf_write,
PerlIOBase_eof,
PerlIOBase_error,
PerlIOBase_clearerr,
- PerlIOBuf_setlinebuf,
+ PerlIOBase_setlinebuf,
PerlIOBuf_get_base,
PerlIOBuf_bufsiz,
PerlIOBuf_get_ptr,
} PerlIOCrlf;
IV
-PerlIOCrlf_pushed(PerlIO *f, const char *mode,const char *arg,STRLEN len)
+PerlIOCrlf_pushed(PerlIO *f, const char *mode,SV *arg)
{
IV code;
PerlIOBase(f)->flags |= PERLIO_F_CRLF;
- code = PerlIOBuf_pushed(f,mode,arg,len);
+ code = PerlIOBuf_pushed(f,mode,arg);
#if 0
PerlIO_debug("PerlIOCrlf_pushed f=%p %s %s fl=%08"UVxf"\n",
f,PerlIOBase(f)->tab->name,(mode) ? mode : "(Null)",
"crlf",
sizeof(PerlIOCrlf),
PERLIO_K_BUFFERED|PERLIO_K_CANCRLF,
- PerlIOBase_fileno,
- PerlIOBuf_open,
PerlIOCrlf_pushed,
PerlIOBase_noop_ok, /* popped */
+ PerlIOBuf_open,
+ NULL,
+ PerlIOBase_fileno,
PerlIOBuf_read, /* generic read works with ptr/cnt lies ... */
PerlIOCrlf_unread, /* Put CR,LF in buffer for each '\n' */
PerlIOCrlf_write, /* Put CR,LF in buffer for each '\n' */
PerlIOBase_eof,
PerlIOBase_error,
PerlIOBase_clearerr,
- PerlIOBuf_setlinebuf,
+ PerlIOBase_setlinebuf,
PerlIOBuf_get_base,
PerlIOBuf_bufsiz,
PerlIOBuf_get_ptr,
"mmap",
sizeof(PerlIOMmap),
PERLIO_K_BUFFERED,
- PerlIOBase_fileno,
- PerlIOBuf_open,
PerlIOBuf_pushed,
PerlIOBase_noop_ok,
+ PerlIOBuf_open,
+ NULL,
+ PerlIOBase_fileno,
PerlIOBuf_read,
PerlIOMmap_unread,
PerlIOMmap_write,
PerlIOBase_eof,
PerlIOBase_error,
PerlIOBase_clearerr,
- PerlIOBuf_setlinebuf,
+ PerlIOBase_setlinebuf,
PerlIOMmap_get_base,
PerlIOBuf_bufsiz,
PerlIOBuf_get_ptr,
}
}
-
-
#undef PerlIO_stdin
PerlIO *
PerlIO_stdin(void)
{
if (!_perlio)
- PerlIO_stdstreams();
+ {
+ dTHX;
+ PerlIO_stdstreams(aTHX);
+ }
return &_perlio[1];
}
PerlIO_stdout(void)
{
if (!_perlio)
- PerlIO_stdstreams();
+ {
+ dTHX;
+ PerlIO_stdstreams(aTHX);
+ }
return &_perlio[2];
}
PerlIO_stderr(void)
{
if (!_perlio)
- PerlIO_stdstreams();
+ {
+ dTHX;
+ PerlIO_stdstreams(aTHX);
+ }
return &_perlio[3];
}
FILE *stdio = PerlSIO_tmpfile();
if (stdio)
{
- PerlIOStdio *s = PerlIOSelf(PerlIO_push(aTHX_ (f = PerlIO_allocate(aTHX)),&PerlIO_stdio,"w+",Nullch,0),PerlIOStdio);
+ PerlIOStdio *s = PerlIOSelf(PerlIO_push(aTHX_ (f = PerlIO_allocate(aTHX)),&PerlIO_stdio,"w+",Nullsv),PerlIOStdio);
s->stdio = stdio;
}
return f;
if (f && len == sizeof(Off_t))
return PerlIO_seek(f,*posn,SEEK_SET);
}
- errno = EINVAL;
+ SETERRNO(EINVAL,SS$_IVCHAN);
return -1;
}
#else
#endif
}
}
- errno = EINVAL;
+ SETERRNO(EINVAL,SS$_IVCHAN);
return -1;
}
#endif