l->next = *f;
l->tab = tab;
*f = l;
- PerlIO_debug("PerlIO_push f=%p %s %s\n",f,tab->name,(mode) ? mode : "(Null)");
+ 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_pop(f);
}
IV
+PerlIOPop_pushed(PerlIO *f, const char *mode, const char *arg, STRLEN len)
+{
+ PerlIO_pop(f);
+ if (*f)
+ {
+ PerlIO_flush(f);
+ PerlIO_pop(f);
+ return 0;
+ }
+ return -1;
+}
+
+IV
PerlIORaw_pushed(PerlIO *f, const char *mode, const char *arg, STRLEN len)
{
+ /* Remove the dummy layer */
+ PerlIO_pop(f);
/* Pop back to bottom layer */
- if (f && *f && *PerlIONext(f))
+ if (f && *f)
{
- PerlIO_flush(PerlIONext(f));
- while (*PerlIONext(f))
+ int code = 0;
+ PerlIO_flush(f);
+ while (!(PerlIOBase(f)->tab->kind & PERLIO_K_RAW))
{
- PerlIO_pop(f);
+ if (*PerlIONext(f))
+ {
+ PerlIO_pop(f);
+ }
+ else
+ {
+ /* Nothing bellow - push unix on top then remove it */
+ if (PerlIO_push(f,PerlIO_default_btm(),mode,arg,len))
+ {
+ PerlIO_pop(PerlIONext(f));
+ }
+ break;
+ }
}
PerlIO_debug(":raw f=%p :%s\n",f,PerlIOBase(f)->tab->name);
return 0;
s++;
if (*s)
{
+ STRLEN llen = 0;
const char *e = s;
const char *as = Nullch;
- const char *ae = Nullch;
- int count = 0;
- while (*e && *e != ':' && !isSPACE(*e))
+ STRLEN alen = 0;
+ if (!isIDFIRST(*s))
{
- if (*e == '(')
- {
- if (!as)
- as = e;
- count++;
- }
- else if (*e == ')')
- {
- if (as && --count == 0)
- ae = e;
- }
- e++;
+ /* 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;
}
- if (e > s)
+ do
{
- if ((e - s) == 3 && strncmp(s,"raw",3) == 0)
+ e++;
+ } while (isALNUM(*e));
+ llen = e-s;
+ if (*e == '(')
+ {
+ int nesting = 1;
+ as = ++e;
+ while (nesting)
{
- /* Pop back to bottom layer */
- if (PerlIONext(f))
+ switch (*e++)
{
- PerlIO_flush(f);
- while (*PerlIONext(f))
- {
- PerlIO_pop(f);
- }
+ 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;
}
- PerlIO_debug(":raw f=%p => :%s\n",f,PerlIOBase(f)->tab->name);
}
- else if ((e - s) == 4 && strncmp(s,"utf8",4) == 0)
- {
- PerlIOBase(f)->flags |= PERLIO_F_UTF8;
- }
- else if ((e - s) == 5 && strncmp(s,"bytes",5) == 0)
- {
- PerlIOBase(f)->flags &= ~PERLIO_F_UTF8;
- }
- else
+ }
+ if (e > s)
+ {
+ SV *layer = PerlIO_find_layer(s,llen);
+ if (layer)
{
- STRLEN len = ((as) ? as : e)-s;
- SV *layer = PerlIO_find_layer(s,len);
- if (layer)
+ PerlIO_funcs *tab = INT2PTR(PerlIO_funcs *, SvIV(SvRV(layer)));
+ if (tab)
{
- PerlIO_funcs *tab = INT2PTR(PerlIO_funcs *, SvIV(SvRV(layer)));
- if (tab)
- {
- if (as && (ae == Nullch)) {
- ae = e;
- Perl_warn(aTHX_ "perlio: argument list not closed for layer \"%.*s\"",(int)(e - s),s);
- }
- len = (as) ? (ae-(as++)-1) : 0;
- if (!PerlIO_push(f,tab,mode,as,len))
- return -1;
- }
+ if (!PerlIO_push(f,tab,mode,as,alen))
+ return -1;
}
- else
- Perl_warn(aTHX_ "perlio: unknown layer \"%.*s\"",(int)len,s);
}
+ else
+ Perl_warn(aTHX_ "perlio: unknown layer \"%.*s\"",(int)llen,s);
}
s = e;
}
PerlIO *
PerlIORaw_fdopen(PerlIO_funcs *self, int fd,const char *mode)
{
- PerlIO_funcs *tab = PerlIO_default_layer(0);
+ PerlIO_funcs *tab = PerlIO_default_btm();
return (*tab->Fdopen)(tab,fd,mode);
}
PerlIO *
PerlIORaw_open(PerlIO_funcs *self, const char *path,const char *mode)
{
- PerlIO_funcs *tab = PerlIO_default_layer(0);
+ PerlIO_funcs *tab = PerlIO_default_btm();
return (*tab->Open)(tab,path,mode);
}
PerlIO_funcs PerlIO_raw = {
"raw",
sizeof(PerlIOl),
- PERLIO_K_DUMMY|PERLIO_K_RAW,
+ PERLIO_K_DUMMY,
NULL,
PerlIORaw_fdopen,
PerlIORaw_open,
return PerlIOSelf(f,PerlIOUnix)->fd;
}
+IV
+PerlIOUnix_pushed(PerlIO *f, const char *mode, const char *arg, STRLEN len)
+{
+ IV code = PerlIOBase_pushed(f,mode,arg,len);
+ if (*PerlIONext(f))
+ {
+ PerlIOUnix *s = PerlIOSelf(f,PerlIOUnix);
+ s->fd = PerlIO_fileno(PerlIONext(f));
+ s->oflags = PerlIOUnix_oflags(mode);
+ }
+ PerlIOBase(f)->flags |= PERLIO_F_OPEN;
+ return code;
+}
+
PerlIO *
PerlIOUnix_fdopen(PerlIO_funcs *self, int fd,const char *mode)
{
PerlIOUnix *s = PerlIOSelf(PerlIO_push(f = PerlIO_allocate(aTHX),self,mode,Nullch,0),PerlIOUnix);
s->fd = fd;
s->oflags = oflags;
- PerlIOBase(f)->flags |= PERLIO_F_OPEN;
}
}
return f;
PerlIOUnix_fdopen,
PerlIOUnix_open,
PerlIOUnix_reopen,
- PerlIOBase_pushed,
+ PerlIOUnix_pushed,
PerlIOBase_noop_ok,
PerlIOUnix_read,
PerlIOBase_unread,
return f;
}
+/* This isn't used yet ... */
+IV
+PerlIOStdio_pushed(PerlIO *f, const char *mode, const char *arg, STRLEN len)
+{
+ if (*PerlIONext(f))
+ {
+ PerlIOStdio *s = PerlIOSelf(f,PerlIOStdio);
+ char tmode[8];
+ FILE *stdio = PerlSIO_fdopen(PerlIO_fileno(PerlIONext(f)),mode = PerlIOStdio_mode(mode,tmode));
+ if (stdio)
+ s->stdio = stdio;
+ else
+ return -1;
+ }
+ return PerlIOBase_pushed(f,mode,arg,len);
+}
+
#undef PerlIO_importFILE
PerlIO *
PerlIO_importFILE(FILE *stdio, int fl)
/* write() the buffer */
STDCHAR *buf = b->buf;
STDCHAR *p = buf;
- int count;
PerlIO *n = PerlIONext(f);
while (p < b->ptr)
{
- count = PerlIO_write(n,p,b->ptr - p);
+ SSize_t count = PerlIO_write(n,p,b->ptr - p);
if (count > 0)
{
p += count;