/* Call the callback or PerlIOBase, and return failure. */
#define Perl_PerlIO_or_Base(f, callback, base, failure, args) \
if (PerlIOValid(f)) { \
- PerlIO_funcs *tab = PerlIOBase(f)->tab; \
+ const PerlIO_funcs *tab = PerlIOBase(f)->tab; \
if (tab && tab->callback) \
return (*tab->callback) args; \
else \
/* Call the callback or fail, and return failure. */
#define Perl_PerlIO_or_fail(f, callback, failure, args) \
if (PerlIOValid(f)) { \
- PerlIO_funcs *tab = PerlIOBase(f)->tab; \
+ const PerlIO_funcs *tab = PerlIOBase(f)->tab; \
if (tab && tab->callback) \
return (*tab->callback) args; \
SETERRNO(EINVAL, LIB_INVARG); \
/* Call the callback or PerlIOBase, and be void. */
#define Perl_PerlIO_or_Base_void(f, callback, base, args) \
if (PerlIOValid(f)) { \
- PerlIO_funcs *tab = PerlIOBase(f)->tab; \
+ const PerlIO_funcs *tab = PerlIOBase(f)->tab; \
if (tab && tab->callback) \
(*tab->callback) args; \
else \
/* Call the callback or fail, and be void. */
#define Perl_PerlIO_or_fail_void(f, callback, args) \
if (PerlIOValid(f)) { \
- PerlIO_funcs *tab = PerlIOBase(f)->tab; \
+ const PerlIO_funcs *tab = PerlIOBase(f)->tab; \
if (tab && tab->callback) \
(*tab->callback) args; \
else \
else \
SETERRNO(EBADF, SS_IVCHAN)
-int
+#ifdef USE_SFIO
+static int
perlsio_binmode(FILE *fp, int iotype, int mode)
{
/*
# endif
#endif
}
+#endif /* sfio */
#ifndef O_ACCMODE
#define O_ACCMODE 3 /* Assume traditional implementation */
int
PerlIO_intmode2str(int rawmode, char *mode, int *writing)
{
- int result = rawmode & O_ACCMODE;
+ const int result = rawmode & O_ACCMODE;
int ix = 0;
int ptype;
switch (result) {
if (*args == &PL_sv_undef)
return PerlIO_tmpfile();
else {
- char *name = SvPV_nolen(*args);
+ const char *name = SvPV_nolen(*args);
if (*mode == IoTYPE_NUMERIC) {
fd = PerlLIO_open3(name, imode, perm);
if (fd >= 0)
- return PerlIO_fdopen(fd, (char *) mode + 1);
+ return PerlIO_fdopen(fd, mode + 1);
}
else if (old) {
return PerlIO_reopen(name, mode, old);
if (items < 2)
Perl_croak(aTHX_ "Usage class->find(name[,load])");
else {
- char *name = SvPV_nolen(ST(1));
+ const char *name = SvPV_nolen(ST(1));
ST(0) = (strEQ(name, "crlf")
|| strEQ(name, "raw")) ? &PL_sv_yes : &PL_sv_undef;
XSRETURN(1);
PerlIO *
PerlIO_importFILE(FILE *stdio, const char *mode)
{
- int fd = fileno(stdio);
+ const int fd = fileno(stdio);
if (!mode || !*mode) {
mode = "r+";
}
FILE *
PerlIO_findFILE(PerlIO *pio)
{
- int fd = PerlIO_fileno(pio);
- FILE *f = fdopen(fd, "r+");
+ const int fd = PerlIO_fileno(pio);
+ FILE * const f = fdopen(fd, "r+");
PerlIO_flush(pio);
if (!f && errno == EINVAL)
f = fdopen(fd, "w");
#include <sys/mman.h>
#endif
-/*
- * Why is this here - not in perlio.h? RMB
- */
-void PerlIO_debug(const char *fmt, ...)
- __attribute__format__(__printf__, 1, 2);
-
void
PerlIO_debug(const char *fmt, ...)
{
dSYS;
va_start(ap, fmt);
if (!PL_perlio_debug_fd && !PL_tainting && PL_uid == PL_euid && PL_gid == PL_egid) {
- char *s = PerlEnv_getenv("PERLIO_DEBUG");
+ const char *s = PerlEnv_getenv("PERLIO_DEBUG");
if (s && *s)
PL_perlio_debug_fd = PerlLIO_open3(s, O_WRONLY | O_CREAT | O_APPEND, 0666);
else
}
if (PL_perlio_debug_fd > 0) {
dTHX;
- const char *s;
+ const char *s = CopFILE(PL_curcop);
+ STRLEN len;
#ifdef USE_ITHREADS
/* Use fixed buffer as sv_catpvf etc. needs SVs */
char buffer[1024];
- STRLEN len;
- s = CopFILE(PL_curcop);
if (!s)
s = "(none)";
- sprintf(buffer, "%.40s:%" IVdf " ", s, (IV) CopLINE(PL_curcop));
- len = strlen(buffer);
+ len = sprintf(buffer, "%.40s:%" IVdf " ", s, (IV) CopLINE(PL_curcop));
vsprintf(buffer+len, fmt, ap);
PerlLIO_write(PL_perlio_debug_fd, buffer, strlen(buffer));
#else
SV *sv = newSVpvn("", 0);
- STRLEN len;
- s = CopFILE(PL_curcop);
if (!s)
s = "(none)";
Perl_sv_catpvf(aTHX_ sv, "%s:%" IVdf " ", s,
PerlIO_fdupopen(pTHX_ PerlIO *f, CLONE_PARAMS *param, int flags)
{
if (PerlIOValid(f)) {
- PerlIO_funcs *tab = PerlIOBase(f)->tab;
+ const PerlIO_funcs * const tab = PerlIOBase(f)->tab;
PerlIO_debug("fdupopen f=%p param=%p\n",(void*)f,(void*)param);
if (tab && tab->Dup)
return (*tab->Dup)(aTHX_ PerlIO_allocate(aTHX), f, param, flags);
return sv;
}
-XS(XS_PerlIO__Layer__NoWarnings)
+static XS(XS_PerlIO__Layer__NoWarnings)
{
/* This is used as a %SIG{__WARN__} handler to supress warnings
during loading of layers.
XSRETURN(0);
}
-XS(XS_PerlIO__Layer__find)
+static XS(XS_PerlIO__Layer__find)
{
dXSARGS;
if (items < 2)
Perl_croak(aTHX_ "Usage class->find(name[,load])");
else {
- STRLEN len = 0;
- char *name = SvPV(ST(1), len);
- bool load = (items > 2) ? SvTRUE(ST(2)) : 0;
+ STRLEN len;
+ const char *name = SvPV(ST(1), len);
+ const bool load = (items > 2) ? SvTRUE(ST(2)) : 0;
PerlIO_funcs *layer = PerlIO_find_layer(aTHX_ name, len, load);
ST(0) =
(layer) ? sv_2mortal(PerlIO_tab_sv(aTHX_ layer)) :
* passed. Even though this means "foo : : bar" is
* seen as an invalid separator character.
*/
- char q = ((*s == '\'') ? '"' : '\'');
+ const char q = ((*s == '\'') ? '"' : '\'');
if (ckWARN(WARN_LAYER))
Perl_warner(aTHX_ packWARN(WARN_LAYER),
"Invalid separator character %c%c%c in PerlIO layer specification %s",
}
}
if (e > s) {
- bool warn_layer = ckWARN(WARN_LAYER);
+ const bool warn_layer = ckWARN(WARN_LAYER);
PerlIO_funcs *layer =
PerlIO_find_layer(aTHX_ s, llen, 1);
if (layer) {
IV
PerlIOPop_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab)
{
+ (void)mode;
+ (void)arg;
+ (void)tab;
if (PerlIOValid(f)) {
PerlIO_flush(f);
PerlIO_pop(aTHX_ f);
NULL,
NULL,
NULL,
+ NULL,
+ NULL,
NULL, /* flush */
NULL, /* fill */
NULL,
IV
PerlIORaw_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab)
{
+ (void)mode;
+ (void)arg;
+ (void)tab;
if (PerlIOValid(f)) {
PerlIO *t;
- PerlIOl *l;
+ const PerlIOl *l;
PerlIO_flush(f);
/*
* Strip all layers that are not suitable for a raw stream
int
Perl_PerlIO_close(pTHX_ PerlIO *f)
{
- int code = PerlIO__close(aTHX_ f);
+ const int code = PerlIO__close(aTHX_ f);
while (PerlIOValid(f)) {
PerlIO_pop(aTHX_ f);
}
if (layers && *layers) {
PerlIO_list_t *av;
if (incdef) {
- IV i = def->cur;
+ IV i;
av = PerlIO_list_alloc(aTHX);
for (i = 0; i < def->cur; i++) {
PerlIO_list_push(aTHX_ av, def->array[i].funcs,
}
}
else {
- PerlIO_list_t *layera = NULL;
+ PerlIO_list_t *layera;
IV n;
PerlIO_funcs *tab = NULL;
if (PerlIOValid(f)) {
{
if (f) {
if (*f) {
- PerlIO_funcs *tab = PerlIOBase(f)->tab;
+ const PerlIO_funcs *tab = PerlIOBase(f)->tab;
if (tab && tab->Flush)
return (*tab->Flush) (aTHX_ f);
PerlIO_has_base(PerlIO *f)
{
if (PerlIOValid(f)) {
- PerlIO_funcs *tab = PerlIOBase(f)->tab;
+ const PerlIO_funcs *tab = PerlIOBase(f)->tab;
if (tab)
return (tab->Get_base != NULL);
PerlIO_fast_gets(PerlIO *f)
{
if (PerlIOValid(f) && (PerlIOBase(f)->flags & PERLIO_F_FASTGETS)) {
- PerlIO_funcs *tab = PerlIOBase(f)->tab;
+ const PerlIO_funcs *tab = PerlIOBase(f)->tab;
if (tab)
return (tab->Set_ptrcnt != NULL);
PerlIO_has_cntptr(PerlIO *f)
{
if (PerlIOValid(f)) {
- PerlIO_funcs *tab = PerlIOBase(f)->tab;
+ const PerlIO_funcs *tab = PerlIOBase(f)->tab;
if (tab)
return (tab->Get_ptr != NULL && tab->Get_cnt != NULL);
PerlIO_canset_cnt(PerlIO *f)
{
if (PerlIOValid(f)) {
- PerlIO_funcs *tab = PerlIOBase(f)->tab;
+ const PerlIO_funcs *tab = PerlIOBase(f)->tab;
if (tab)
return (tab->Set_ptrcnt != NULL);
IV
PerlIOUtf8_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab)
{
+ (void)mode;
+ (void)arg;
if (PerlIOValid(f)) {
if (tab->kind & PERLIO_K_UTF8)
PerlIOBase(f)->flags |= PERLIO_F_UTF8;
NULL,
NULL,
NULL,
+ NULL,
+ NULL,
NULL, /* flush */
NULL, /* fill */
NULL,
NULL,
NULL,
NULL,
+ NULL,
+ NULL,
NULL, /* flush */
NULL, /* fill */
NULL,
PerlIO *old, int narg, SV **args)
{
PerlIO_funcs *tab = PerlIO_default_btm();
+ (void)self;
if (tab && tab->Open)
return (*tab->Open) (aTHX_ tab, layers, n - 1, mode, fd, imode, perm,
old, narg, args);
NULL,
NULL,
NULL,
+ NULL,
+ NULL,
NULL, /* flush */
NULL, /* fill */
NULL,
{
char *s = buf;
if (PerlIOValid(f)) {
- IV flags = PerlIOBase(f)->flags;
+ const IV flags = PerlIOBase(f)->flags;
if (flags & PERLIO_F_APPEND) {
*s++ = 'a';
if (flags & PERLIO_F_CANREAD) {
IV
PerlIOBase_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab)
{
- PerlIOl *l = PerlIOBase(f);
-#if 0
- const char *omode = mode;
- char temp[8];
-#endif
+ PerlIOl * const l = PerlIOBase(f);
+ (void)arg;
+
l->flags &= ~(PERLIO_F_CANREAD | PERLIO_F_CANWRITE |
PERLIO_F_TRUNCATE | PERLIO_F_APPEND);
if (tab->Set_ptrcnt != NULL)
IV
PerlIOBase_popped(pTHX_ PerlIO *f)
{
+ (void)f;
return 0;
}
/*
* Save the position as current head considers it
*/
- Off_t old = PerlIO_tell(f);
- SSize_t done;
+ const Off_t old = PerlIO_tell(f);
PerlIO_push(aTHX_ f, PERLIO_FUNCS_CAST(&PerlIO_pending), "r", Nullsv);
PerlIOSelf(f, PerlIOBuf)->posn = old;
- done = PerlIOBuf_unread(aTHX_ f, vbuf, count);
- return done;
+ return PerlIOBuf_unread(aTHX_ f, vbuf, count);
}
SSize_t
IV
PerlIOBase_noop_ok(pTHX_ PerlIO *f)
{
+ (void)f;
return 0;
}
IV
PerlIOBase_noop_fail(pTHX_ PerlIO *f)
{
+ (void)f;
return -1;
}
PerlIOBase(f)->flags &=
~(PERLIO_F_CANREAD | PERLIO_F_CANWRITE | PERLIO_F_OPEN);
while (PerlIOValid(n)) {
- PerlIO_funcs *tab = PerlIOBase(n)->tab;
+ const PerlIO_funcs * const tab = PerlIOBase(n)->tab;
if (tab && tab->Close) {
if ((*tab->Close)(aTHX_ n) != 0)
code = -1;
{
PerlIO *nexto = PerlIONext(o);
if (PerlIOValid(nexto)) {
- PerlIO_funcs *tab = PerlIOBase(nexto)->tab;
+ const PerlIO_funcs * const tab = PerlIOBase(nexto)->tab;
if (tab && tab->Dup)
f = (*tab->Dup)(aTHX_ f, nexto, param, flags);
else
static void
PerlIOUnix_setfd(pTHX_ PerlIO *f, int fd, int imode)
{
- PerlIOUnix *s = PerlIOSelf(f, PerlIOUnix);
+ PerlIOUnix * const s = PerlIOSelf(f, PerlIOUnix);
#if defined(WIN32)
Stat_t st;
if (PerlLIO_fstat(fd, &st) == 0) {
IV
PerlIOUnix_seek(pTHX_ PerlIO *f, Off_t offset, int whence)
{
- int fd = PerlIOSelf(f, PerlIOUnix)->fd;
+ const int fd = PerlIOSelf(f, PerlIOUnix)->fd;
Off_t new_loc;
if (PerlIOBase(f)->flags & PERLIO_F_NOTREG) {
#ifdef ESPIPE
(*PerlIOBase(f)->tab->Close)(aTHX_ f);
}
if (narg > 0) {
- char *path = SvPV_nolen(*args);
if (*mode == IoTYPE_NUMERIC)
mode++;
else {
perm = 0666;
}
if (imode != -1) {
+ const char *path = SvPV_nolen(*args);
fd = PerlLIO_open3(path, imode, perm);
}
}
SSize_t
PerlIOUnix_read(pTHX_ PerlIO *f, void *vbuf, Size_t count)
{
- int fd = PerlIOSelf(f, PerlIOUnix)->fd;
+ const int fd = PerlIOSelf(f, PerlIOUnix)->fd;
#ifdef PERLIO_STD_SPECIAL
if (fd == 0)
return PERLIO_STD_IN(fd, vbuf, count);
SSize_t
PerlIOUnix_write(pTHX_ PerlIO *f, const void *vbuf, Size_t count)
{
- int fd = PerlIOSelf(f, PerlIOUnix)->fd;
+ const int fd = PerlIOSelf(f, PerlIOUnix)->fd;
#ifdef PERLIO_STD_SPECIAL
if (fd == 1 || fd == 2)
return PERLIO_STD_OUT(fd, vbuf, count);
#endif
while (1) {
- SSize_t len = PerlLIO_write(fd, vbuf, count);
+ const SSize_t len = PerlLIO_write(fd, vbuf, count);
if (len >= 0 || errno != EINTR) {
if (len < 0) {
if (errno != EAGAIN) {
IV
PerlIOUnix_close(pTHX_ PerlIO *f)
{
- int fd = PerlIOSelf(f, PerlIOUnix)->fd;
+ const int fd = PerlIOSelf(f, PerlIOUnix)->fd;
int code = 0;
if (PerlIOBase(f)->flags & PERLIO_F_OPEN) {
if (PerlIOUnix_refcnt_dec(fd) > 0) {
char *
PerlIOStdio_mode(const char *mode, char *tmode)
{
- char *ret = tmode;
+ char * const ret = tmode;
if (mode) {
while (*mode) {
*tmode++ = *mode++;
PerlIO_pop(aTHX_ f);
return 0;
} else {
- int fd = PerlIO_fileno(n);
+ const int fd = PerlIO_fileno(n);
char tmode[8];
FILE *stdio;
if (fd >= 0 && (stdio = PerlSIO_fdopen(fd,
Note that the errno value set by a failing fdopen
varies between stdio implementations.
*/
- int fd = PerlLIO_dup(fileno(stdio));
+ const int fd = PerlLIO_dup(fileno(stdio));
FILE *f2 = PerlSIO_fdopen(fd, (mode = "r+"));
if (!f2) {
f2 = PerlSIO_fdopen(fd, (mode = "w"));
{
char tmode[8];
if (PerlIOValid(f)) {
- char *path = SvPV_nolen(*args);
+ const char *path = SvPV_nolen(*args);
PerlIOStdio *s = PerlIOSelf(f, PerlIOStdio);
FILE *stdio;
PerlIOUnix_refcnt_dec(fileno(s->stdio));
}
else {
if (narg > 0) {
- char *path = SvPV_nolen(*args);
+ const char *path = SvPV_nolen(*args);
if (*mode == IoTYPE_NUMERIC) {
mode++;
fd = PerlLIO_open3(path, imode, perm);
PerlIOStdio_mode(mode, tmode));
}
if (stdio) {
- PerlIOStdio *s;
if (!f) {
f = PerlIO_allocate(aTHX);
}
if ((f = PerlIO_push(aTHX_ f, self, mode, PerlIOArg))) {
- s = PerlIOSelf(f, PerlIOStdio);
+ PerlIOStdio *s = PerlIOSelf(f, PerlIOStdio);
s->stdio = stdio;
PerlIOUnix_refcnt_inc(fileno(s->stdio));
}
*/
if ((f = PerlIOBase_dup(aTHX_ f, o, param, flags))) {
FILE *stdio = PerlIOSelf(o, PerlIOStdio)->stdio;
- int fd = fileno(stdio);
+ const int fd = fileno(stdio);
char mode[8];
if (flags & PERLIO_DUP_FD) {
- int dfd = PerlLIO_dup(fileno(stdio));
+ const int dfd = PerlLIO_dup(fileno(stdio));
if (dfd >= 0) {
stdio = PerlSIO_fdopen(dfd, PerlIO_modestr(o,mode));
goto set_this;
return -1;
}
else {
- int fd = fileno(stdio);
+ const int fd = fileno(stdio);
int socksfd = 0;
int invalidate = 0;
IV result = 0;
* Perl is expecting PerlIO_getc() to fill the buffer Linux's
* stdio does not do that for fread()
*/
- int ch = PerlSIO_fgetc(s);
+ const int ch = PerlSIO_fgetc(s);
if (ch != EOF) {
*buf = ch;
got = 1;
STDCHAR *eptr = (STDCHAR*)PerlSIO_get_ptr(s);
STDCHAR *buf = ((STDCHAR *) vbuf) + count;
while (count > 0) {
- int ch = *--buf & 0xFF;
+ const int ch = *--buf & 0xFF;
if (ungetc(ch,s) != ch) {
/* ungetc did not work */
break;
PerlIOBuf_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab)
{
PerlIOBuf *b = PerlIOSelf(f, PerlIOBuf);
- int fd = PerlIO_fileno(f);
+ const int fd = PerlIO_fileno(f);
if (fd >= 0 && PerlLIO_isatty(fd)) {
PerlIOBase(f)->flags |= PERLIO_F_LINEBUF | PERLIO_F_TTY;
}
if (*PerlIONext(f)) {
- Off_t posn = PerlIO_tell(PerlIONext(f));
+ const Off_t posn = PerlIO_tell(PerlIONext(f));
if (posn != (Off_t) - 1) {
b->posn = posn;
}
/*
* write() the buffer
*/
- STDCHAR *buf = b->buf;
- STDCHAR *p = buf;
+ const STDCHAR *buf = b->buf;
+ const STDCHAR *p = buf;
while (p < b->ptr) {
SSize_t count = PerlIO_write(n, p, b->ptr - p);
if (count > 0) {
SSize_t
PerlIOBuf_read(pTHX_ PerlIO *f, void *vbuf, Size_t count)
{
- PerlIOBuf *b = PerlIOSelf(f, PerlIOBuf);
if (PerlIOValid(f)) {
+ const PerlIOBuf *b = PerlIOSelf(f, PerlIOBuf);
if (!b->ptr)
PerlIO_get_base(f);
return PerlIOBase_read(aTHX_ f, vbuf, count);
SSize_t
PerlIOBuf_write(pTHX_ PerlIO *f, const void *vbuf, Size_t count)
{
- PerlIOBuf *b = PerlIOSelf(f, PerlIOBuf);
+ PerlIOBuf * const b = PerlIOSelf(f, PerlIOBuf);
const STDCHAR *buf = (const STDCHAR *) vbuf;
const STDCHAR *flushptr = buf;
Size_t written = 0;
{
IV code;
if ((code = PerlIO_flush(f)) == 0) {
- PerlIOBuf *b = PerlIOSelf(f, PerlIOBuf);
PerlIOBase(f)->flags &= ~PERLIO_F_EOF;
code = PerlIO_seek(PerlIONext(f), offset, whence);
if (code == 0) {
+ PerlIOBuf *b = PerlIOSelf(f, PerlIOBuf);
b->posn = PerlIO_tell(PerlIONext(f));
}
}
IV
PerlIOBuf_popped(pTHX_ PerlIO *f)
{
- IV code = PerlIOBase_popped(aTHX_ f);
- PerlIOBuf *b = PerlIOSelf(f, PerlIOBuf);
+ const IV code = PerlIOBase_popped(aTHX_ f);
+ PerlIOBuf * const b = PerlIOSelf(f, PerlIOBuf);
if (b->buf && b->buf != (STDCHAR *) & b->oneword) {
Safefree(b->buf);
}
IV
PerlIOBuf_close(pTHX_ PerlIO *f)
{
- IV code = PerlIOBase_close(aTHX_ f);
- PerlIOBuf *b = PerlIOSelf(f, PerlIOBuf);
+ const IV code = PerlIOBase_close(aTHX_ f);
+ PerlIOBuf * const b = PerlIOSelf(f, PerlIOBuf);
if (b->buf && b->buf != (STDCHAR *) & b->oneword) {
Safefree(b->buf);
}
if (!b->buf) {
if (!b->bufsiz)
b->bufsiz = 4096;
- b->buf =
- Newz('B',b->buf,b->bufsiz, STDCHAR);
+ b->buf = Newz('B',b->buf,b->bufsiz, STDCHAR);
if (!b->buf) {
b->buf = (STDCHAR *) & b->oneword;
b->bufsiz = sizeof(b->oneword);
IV
PerlIOPending_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab)
{
- IV code = PerlIOBase_pushed(aTHX_ f, mode, arg, tab);
+ const IV code = PerlIOBase_pushed(aTHX_ f, mode, arg, tab);
PerlIOl *l = PerlIOBase(f);
/*
* Our PerlIO_fast_gets must match what we are pushed on, or sv_gets()
if (avail > 0)
got = PerlIOBuf_read(aTHX_ f, vbuf, avail);
if (got >= 0 && got < (SSize_t)count) {
- SSize_t more =
+ const SSize_t more =
PerlIO_read(f, ((STDCHAR *) vbuf) + got, count - got);
if (more >= 0 || got == 0)
got += more;
NULL,
PerlIOBase_fileno,
PerlIOBuf_dup,
- PerlIOBuf_read, /* generic read works with ptr/cnt lies
- * ... */
+ 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' */
PerlIOBuf_seek,
PerlIOMmap_map(pTHX_ PerlIO *f)
{
dVAR;
- PerlIOMmap *m = PerlIOSelf(f, PerlIOMmap);
- IV flags = PerlIOBase(f)->flags;
+ PerlIOMmap * const m = PerlIOSelf(f, PerlIOMmap);
+ const IV flags = PerlIOBase(f)->flags;
IV code = 0;
if (m->len)
abort();
if (flags & PERLIO_F_CANREAD) {
PerlIOBuf *b = PerlIOSelf(f, PerlIOBuf);
- int fd = PerlIO_fileno(f);
+ const int fd = PerlIO_fileno(f);
Stat_t st;
code = Fstat(fd, &st);
if (code == 0 && S_ISREG(st.st_mode)) {
SSize_t
PerlIOMmap_write(pTHX_ PerlIO *f, const void *vbuf, Size_t count)
{
- PerlIOMmap *m = PerlIOSelf(f, PerlIOMmap);
- PerlIOBuf *b = &m->base;
+ PerlIOMmap * const m = PerlIOSelf(f, PerlIOMmap);
+ PerlIOBuf * const b = &m->base;
+
if (!b->buf || !(PerlIOBase(f)->flags & PERLIO_F_WRBUF)) {
/*
* No, or wrong sort of, buffer
{
dTHX;
STDCHAR buf[1];
- SSize_t count = PerlIO_read(f, buf, 1);
- if (count == 1) {
+ if ( 1 == PerlIO_read(f, buf, 1) ) {
return (unsigned char) buf[0];
}
return EOF;
dTHX;
PerlIO *f = NULL;
#ifdef WIN32
- int fd = win32_tmpfd();
+ const int fd = win32_tmpfd();
if (fd >= 0)
f = PerlIO_fdopen(fd, "w+b");
#else /* WIN32 */
/*
* I have no idea how portable mkstemp() is ... NI-S
*/
- int fd = mkstemp(SvPVX(sv));
+ const int fd = mkstemp(SvPVX(sv));
if (fd >= 0) {
f = PerlIO_fdopen(fd, "w+");
if (f)
PerlIO_vsprintf(char *s, int n, const char *fmt, va_list ap)
{
dVAR;
- int val = vsprintf(s, fmt, ap);
+ const int val = vsprintf(s, fmt, ap);
if (n >= 0) {
if (strlen(s) >= (STRLEN) n) {
dTHX;
return result;
}
#endif
-
-
-
-
-
-
-
-
#endif
/*--------------------------------------------------------------------------------------*/
-/* Generic, or stub layer functions */
-
-PERL_EXPORT_C IV PerlIOBase_fileno(pTHX_ PerlIO *f);
-PERL_EXPORT_C PerlIO *PerlIOBase_dup(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param, int flags);
-PERL_EXPORT_C IV PerlIOBase_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab);
-PERL_EXPORT_C IV PerlIOBase_popped(pTHX_ PerlIO *f);
-PERL_EXPORT_C IV PerlIOBase_binmode(pTHX_ PerlIO *f);
-PERL_EXPORT_C SSize_t PerlIOBase_read(pTHX_ PerlIO *f,
- void *vbuf, Size_t count);
-PERL_EXPORT_C SSize_t PerlIOBase_unread(pTHX_ PerlIO *f,
- const void *vbuf, Size_t count);
-PERL_EXPORT_C IV PerlIOBase_eof(pTHX_ PerlIO *f);
-PERL_EXPORT_C IV PerlIOBase_error(pTHX_ PerlIO *f);
-PERL_EXPORT_C void PerlIOBase_clearerr(pTHX_ PerlIO *f);
-PERL_EXPORT_C IV PerlIOBase_close(pTHX_ PerlIO *f);
-PERL_EXPORT_C void PerlIOBase_setlinebuf(pTHX_ PerlIO *f);
-PERL_EXPORT_C void PerlIOBase_flush_linebuf(pTHX);
-
-PERL_EXPORT_C IV PerlIOBase_noop_ok(pTHX_ PerlIO *f);
-PERL_EXPORT_C IV PerlIOBase_noop_fail(pTHX_ PerlIO *f);
-
-/*--------------------------------------------------------------------------------------*/
/* perlio buffer layer
As this is reasonably generic its struct and "methods" are declared here
so they can be used to "inherit" from it.
PERL_EXPORT_C int PerlIO_apply_layera(pTHX_ PerlIO *f, const char *mode,
PerlIO_list_t *layers, IV n, IV max);
PERL_EXPORT_C int PerlIO_parse_layers(pTHX_ PerlIO_list_t *av, const char *names);
-PERL_EXPORT_C void PerlIO_list_free(pTHX_ PerlIO_list_t *list);
PERL_EXPORT_C PerlIO_funcs *PerlIO_layer_fetch(pTHX_ PerlIO_list_t *av, IV n, PerlIO_funcs *def);
+PERL_EXPORT_C void PerlIO_debug(const char *fmt, ...)
+ __attribute__format__(__printf__, 1, 2);
PERL_EXPORT_C SV *PerlIO_sv_dup(pTHX_ SV *arg, CLONE_PARAMS *param);
-PERL_EXPORT_C PerlIO *PerlIOBuf_open(pTHX_ PerlIO_funcs *self,
- PerlIO_list_t *layers, IV n,
- const char *mode, int fd, int imode,
- int perm, PerlIO *old, int narg, SV **args);
-PERL_EXPORT_C IV PerlIOBuf_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab);
-PERL_EXPORT_C IV PerlIOBuf_popped(pTHX_ PerlIO *f);
-PERL_EXPORT_C PerlIO *PerlIOBuf_dup(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param, int flags);
-PERL_EXPORT_C SSize_t PerlIOBuf_read(pTHX_ PerlIO *f, void *vbuf, Size_t count);
-PERL_EXPORT_C SSize_t PerlIOBuf_unread(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
-PERL_EXPORT_C SSize_t PerlIOBuf_write(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
-PERL_EXPORT_C IV PerlIOBuf_seek(pTHX_ PerlIO *f, Off_t offset, int whence);
-PERL_EXPORT_C Off_t PerlIOBuf_tell(pTHX_ PerlIO *f);
-PERL_EXPORT_C IV PerlIOBuf_close(pTHX_ PerlIO *f);
-PERL_EXPORT_C IV PerlIOBuf_flush(pTHX_ PerlIO *f);
-PERL_EXPORT_C IV PerlIOBuf_fill(pTHX_ PerlIO *f);
-PERL_EXPORT_C STDCHAR *PerlIOBuf_get_base(pTHX_ PerlIO *f);
-PERL_EXPORT_C Size_t PerlIOBuf_bufsiz(pTHX_ PerlIO *f);
-PERL_EXPORT_C STDCHAR *PerlIOBuf_get_ptr(pTHX_ PerlIO *f);
-PERL_EXPORT_C SSize_t PerlIOBuf_get_cnt(pTHX_ PerlIO *f);
-PERL_EXPORT_C void PerlIOBuf_set_ptrcnt(pTHX_ PerlIO *f, STDCHAR * ptr, SSize_t cnt);
-
-PERL_EXPORT_C int PerlIOUnix_oflags(const char *mode);
+PERL_EXPORT_C void PerlIO_cleantable(pTHX_ PerlIO **tablep);
+PERL_EXPORT_C SV * PerlIO_tab_sv(pTHX_ PerlIO_funcs *tab);
+PERL_EXPORT_C void PerlIO_default_buffer(pTHX_ PerlIO_list_t *av);
+PERL_EXPORT_C void PerlIO_stdstreams(pTHX);
+PERL_EXPORT_C int PerlIO__close(pTHX_ PerlIO *f);
+PERL_EXPORT_C PerlIO_list_t * PerlIO_resolve_layers(pTHX_ const char *layers, const char *mode, int narg, SV **args);
+PERL_EXPORT_C PerlIO_funcs * PerlIO_default_layer(pTHX_ I32 n);
+PERL_EXPORT_C PerlIO_list_t * PerlIO_default_layers(pTHX);
+PERL_EXPORT_C PerlIO * PerlIO_reopen(const char *path, const char *mode, PerlIO *f);
+PERL_EXPORT_C int PerlIO_vsprintf(char *s, int n, const char *fmt, va_list ap);
+
+PERL_EXPORT_C PerlIO_list_t *PerlIO_list_alloc(pTHX);
+PERL_EXPORT_C PerlIO_list_t *PerlIO_clone_list(pTHX_ PerlIO_list_t *proto, CLONE_PARAMS *param);
+PERL_EXPORT_C void PerlIO_list_free(pTHX_ PerlIO_list_t *list);
+PERL_EXPORT_C void PerlIO_list_push(pTHX_ PerlIO_list_t *list, PerlIO_funcs *funcs, SV *arg);
+PERL_EXPORT_C void PerlIO_list_free(pTHX_ PerlIO_list_t *list);
/*--------------------------------------------------------------------------------------*/
+/* Generic, or stub layer functions */
+
+PERL_EXPORT_C IV PerlIOBase_binmode(pTHX_ PerlIO *f);
+PERL_EXPORT_C void PerlIOBase_clearerr(pTHX_ PerlIO *f);
+PERL_EXPORT_C IV PerlIOBase_close(pTHX_ PerlIO *f);
+PERL_EXPORT_C PerlIO * PerlIOBase_dup(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param, int flags);
+PERL_EXPORT_C IV PerlIOBase_eof(pTHX_ PerlIO *f);
+PERL_EXPORT_C IV PerlIOBase_error(pTHX_ PerlIO *f);
+PERL_EXPORT_C IV PerlIOBase_fileno(pTHX_ PerlIO *f);
+PERL_EXPORT_C void PerlIOBase_flush_linebuf(pTHX);
+PERL_EXPORT_C IV PerlIOBase_noop_fail(pTHX_ PerlIO *f);
+PERL_EXPORT_C IV PerlIOBase_noop_ok(pTHX_ PerlIO *f);
+PERL_EXPORT_C IV PerlIOBase_popped(pTHX_ PerlIO *f);
+PERL_EXPORT_C IV PerlIOBase_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab);
+PERL_EXPORT_C SSize_t PerlIOBase_read(pTHX_ PerlIO *f, void *vbuf, Size_t count);
+PERL_EXPORT_C void PerlIOBase_setlinebuf(pTHX_ PerlIO *f);
+PERL_EXPORT_C SSize_t PerlIOBase_unread(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
+
+/* Buf */
+PERL_EXPORT_C Size_t PerlIOBuf_bufsiz(pTHX_ PerlIO *f);
+PERL_EXPORT_C IV PerlIOBuf_close(pTHX_ PerlIO *f);
+PERL_EXPORT_C PerlIO * PerlIOBuf_dup(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param, int flags);
+PERL_EXPORT_C IV PerlIOBuf_fill(pTHX_ PerlIO *f);
+PERL_EXPORT_C IV PerlIOBuf_flush(pTHX_ PerlIO *f);
+PERL_EXPORT_C STDCHAR * PerlIOBuf_get_base(pTHX_ PerlIO *f);
+PERL_EXPORT_C SSize_t PerlIOBuf_get_cnt(pTHX_ PerlIO *f);
+PERL_EXPORT_C STDCHAR * PerlIOBuf_get_ptr(pTHX_ PerlIO *f);
+PERL_EXPORT_C PerlIO * PerlIOBuf_open(pTHX_ PerlIO_funcs *self, PerlIO_list_t *layers, IV n, const char *mode, int fd, int imode, int perm, PerlIO *old, int narg, SV **args);
+PERL_EXPORT_C IV PerlIOBuf_popped(pTHX_ PerlIO *f);
+PERL_EXPORT_C IV PerlIOBuf_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab);
+PERL_EXPORT_C SSize_t PerlIOBuf_read(pTHX_ PerlIO *f, void *vbuf, Size_t count);
+PERL_EXPORT_C IV PerlIOBuf_seek(pTHX_ PerlIO *f, Off_t offset, int whence);
+PERL_EXPORT_C void PerlIOBuf_set_ptrcnt(pTHX_ PerlIO *f, STDCHAR * ptr, SSize_t cnt);
+PERL_EXPORT_C Off_t PerlIOBuf_tell(pTHX_ PerlIO *f);
+PERL_EXPORT_C SSize_t PerlIOBuf_unread(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
+PERL_EXPORT_C SSize_t PerlIOBuf_write(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
+
+/* Crlf */
+PERL_EXPORT_C IV PerlIOCrlf_binmode(pTHX_ PerlIO *f);
+PERL_EXPORT_C IV PerlIOCrlf_flush(pTHX_ PerlIO *f);
+PERL_EXPORT_C SSize_t PerlIOCrlf_get_cnt(pTHX_ PerlIO *f);
+PERL_EXPORT_C IV PerlIOCrlf_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab);
+PERL_EXPORT_C void PerlIOCrlf_set_ptrcnt(pTHX_ PerlIO *f, STDCHAR * ptr, SSize_t cnt);
+PERL_EXPORT_C SSize_t PerlIOCrlf_unread(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
+PERL_EXPORT_C SSize_t PerlIOCrlf_unread(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
+PERL_EXPORT_C SSize_t PerlIOCrlf_write(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
+
+/* Mmap */
+PERL_EXPORT_C IV PerlIOMmap_close(pTHX_ PerlIO *f);
+PERL_EXPORT_C PerlIO * PerlIOMmap_dup(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param, int flags);
+PERL_EXPORT_C IV PerlIOMmap_fill(pTHX_ PerlIO *f);
+PERL_EXPORT_C IV PerlIOMmap_flush(pTHX_ PerlIO *f);
+PERL_EXPORT_C STDCHAR * PerlIOMmap_get_base(pTHX_ PerlIO *f);
+PERL_EXPORT_C IV PerlIOMmap_map(pTHX_ PerlIO *f);
+PERL_EXPORT_C IV PerlIOMmap_unmap(pTHX_ PerlIO *f);
+PERL_EXPORT_C SSize_t PerlIOMmap_unread(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
+PERL_EXPORT_C SSize_t PerlIOMmap_write(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
+
+/* Pending */
+PERL_EXPORT_C IV PerlIOPending_close(pTHX_ PerlIO *f);
+PERL_EXPORT_C IV PerlIOPending_fill(pTHX_ PerlIO *f);
+PERL_EXPORT_C IV PerlIOPending_flush(pTHX_ PerlIO *f);
+PERL_EXPORT_C IV PerlIOPending_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab);
+PERL_EXPORT_C SSize_t PerlIOPending_read(pTHX_ PerlIO *f, void *vbuf, Size_t count);
+PERL_EXPORT_C IV PerlIOPending_seek(pTHX_ PerlIO *f, Off_t offset, int whence);
+PERL_EXPORT_C void PerlIOPending_set_ptrcnt(pTHX_ PerlIO *f, STDCHAR * ptr, SSize_t cnt);
+
+/* Pop */
+PERL_EXPORT_C IV PerlIOPop_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab);
+
+/* Raw */
+PERL_EXPORT_C PerlIO * PerlIORaw_open(pTHX_ PerlIO_funcs *self, PerlIO_list_t *layers, IV n, const char *mode, int fd, int imode, int perm, PerlIO *old, int narg, SV **args);
+PERL_EXPORT_C IV PerlIORaw_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab);
+
+/* Stdio */
+PERL_EXPORT_C void PerlIOStdio_clearerr(pTHX_ PerlIO *f);
+PERL_EXPORT_C IV PerlIOStdio_close(pTHX_ PerlIO *f);
+PERL_EXPORT_C PerlIO * PerlIOStdio_dup(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param, int flags);
+PERL_EXPORT_C IV PerlIOStdio_eof(pTHX_ PerlIO *f);
+PERL_EXPORT_C IV PerlIOStdio_error(pTHX_ PerlIO *f);
+PERL_EXPORT_C IV PerlIOStdio_fileno(pTHX_ PerlIO *f);
+PERL_EXPORT_C IV PerlIOStdio_fill(pTHX_ PerlIO *f);
+PERL_EXPORT_C IV PerlIOStdio_flush(pTHX_ PerlIO *f);
+PERL_EXPORT_C STDCHAR * PerlIOStdio_get_base(pTHX_ PerlIO *f);
+PERL_EXPORT_C char * PerlIOStdio_mode(const char *mode, char *tmode);
+PERL_EXPORT_C PerlIO * PerlIOStdio_open(pTHX_ PerlIO_funcs *self, PerlIO_list_t *layers, IV n, const char *mode, int fd, int imode, int perm, PerlIO *f, int narg, SV **args);
+PERL_EXPORT_C IV PerlIOStdio_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab);
+PERL_EXPORT_C SSize_t PerlIOStdio_read(pTHX_ PerlIO *f, void *vbuf, Size_t count);
+PERL_EXPORT_C IV PerlIOStdio_seek(pTHX_ PerlIO *f, Off_t offset, int whence);
+PERL_EXPORT_C void PerlIOStdio_setlinebuf(pTHX_ PerlIO *f);
+PERL_EXPORT_C Off_t PerlIOStdio_tell(pTHX_ PerlIO *f);
+PERL_EXPORT_C SSize_t PerlIOStdio_unread(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
+PERL_EXPORT_C SSize_t PerlIOStdio_write(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
+
+/* Unix */
+PERL_EXPORT_C IV PerlIOUnix_close(pTHX_ PerlIO *f);
+PERL_EXPORT_C PerlIO * PerlIOUnix_dup(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param, int flags);
+PERL_EXPORT_C IV PerlIOUnix_fileno(pTHX_ PerlIO *f);
+PERL_EXPORT_C int PerlIOUnix_oflags(const char *mode);
+PERL_EXPORT_C PerlIO * PerlIOUnix_open(pTHX_ PerlIO_funcs *self, PerlIO_list_t *layers, IV n, const char *mode, int fd, int imode, int perm, PerlIO *f, int narg, SV **args);
+PERL_EXPORT_C IV PerlIOUnix_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab);
+PERL_EXPORT_C SSize_t PerlIOUnix_read(pTHX_ PerlIO *f, void *vbuf, Size_t count);
+PERL_EXPORT_C int PerlIOUnix_refcnt_dec(int fd);
+PERL_EXPORT_C void PerlIOUnix_refcnt_inc(int fd);
+PERL_EXPORT_C IV PerlIOUnix_seek(pTHX_ PerlIO *f, Off_t offset, int whence);
+PERL_EXPORT_C Off_t PerlIOUnix_tell(pTHX_ PerlIO *f);
+PERL_EXPORT_C SSize_t PerlIOUnix_write(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
+
+/* Utf8 */
+PERL_EXPORT_C IV PerlIOUtf8_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab);
#endif /* _PERLIOL_H */