int code = 0;
if (f)
{
- PerlIO_debug(__FUNCTION__ " f=%p flags=%08X c=%d buf=%p ptr=%p\n",
- f,f->flags,(f->ptr-f->buf),f->buf,f->ptr);
if (f->flags & PERLIO_F_WRBUF)
{
/* write() the buffer */
else
{
int i;
- for (i=_perlio_size; i >= 0; i--)
+ for (i=_perlio_size-1; i >= 0; i--)
{
if ((f = _perlio[i]))
{
PerlIO_oflags(const char *mode)
{
int oflags = -1;
- PerlIO_debug(__FUNCTION__ " %s = ",mode);
switch(*mode)
{
case 'r':
errno = EINVAL;
oflags = -1;
}
- PerlIO_debug(" %X '%s'\n",oflags,mode);
return oflags;
}
while (i < _perlio_size)
{
f = table[i];
- PerlIO_debug(__FUNCTION__ " try %d %p\n",i,f);
if (!f)
{
Newz('F',f,1,PerlIO);
f->flags |= (PERLIO_F_OPEN|PERLIO_F_USED);
}
}
- PerlIO_debug(__FUNCTION__ " fd=%d m=%s f=%p\n",fd,mode,f);
return f;
}
{
/* Close all the files */
int i;
- PerlIO_debug(__FUNCTION__ "\n");
for (i=_perlio_size-1; i >= 0; i--)
{
PerlIO *f = _perlio[i];
int fd = open(path,oflags,0666);
if (fd >= 0)
{
- PerlIO_debug(__FUNCTION__ "fd=%d\n",fd);
f = PerlIO_fdopen(fd,mode);
if (!f)
close(fd);
}
}
- PerlIO_debug(__FUNCTION__ " path=%s m=%s f=%p\n",path,mode,f);
return f;
}
PerlIO *
PerlIO_reopen(const char *path, const char *mode, PerlIO *f)
{
- PerlIO_debug(__FUNCTION__ " n=%s m=%s f=%p\n",path,mode,f);
if (f)
{
int oflags = PerlIO_oflags(mode);
int fd = open(path,oflags,0666);
if (fd >= 0)
{
- PerlIO_debug(__FUNCTION__ "fd=%d\n",fd);
f->oflags = oflags;
f->flags |= (PERLIO_F_OPEN|PERLIO_F_USED);
}
PerlIO_fdopen(1,"w");
PerlIO_fdopen(2,"w");
}
- PerlIO_debug(__FUNCTION__ "\n");
}
#undef PerlIO_stdin
*--(f->ptr) = ch;
return ch;
}
- PerlIO_debug(__FUNCTION__ " f=%p c=%c - cannot\n",f,ch);
return -1;
}
Size_t got = 0;
if (!f->ptr)
PerlIO_alloc_buf(f);
-
+ if ((f->oflags & (O_RDONLY|O_WRONLY|O_RDWR)) == O_WRONLY)
+ return 0;
while (count > 0)
{
SSize_t avail = (f->end - f->ptr);
{
const STDCHAR *buf = (const STDCHAR *) vbuf;
Size_t written = 0;
- PerlIO_debug(__FUNCTION__ " f=%p c=%d\n",f,count);
if (f)
{
if (!f->buf)
PerlIO_alloc_buf(f);
+ if ((f->oflags & (O_RDONLY|O_WRONLY|O_RDWR)) == O_RDONLY)
+ return 0;
while (count > 0)
{
SSize_t avail = f->bufsiz - (f->ptr - f->buf);
PerlIO_putc(PerlIO *f, int ch)
{
STDCHAR buf = ch;
- PerlIO_write(f,&ch,1);
+ PerlIO_write(f,&buf,1);
}
#undef PerlIO_tell
Off_t posn = f->posn;
if (f->buf)
posn += (f->ptr - f->buf);
- PerlIO_debug(__FUNCTION__ " f=%p b=%ld a=%ld\n",f,(long)f->posn,(long)posn);
return posn;
}
PerlIO_seek(PerlIO *f, Off_t offset, int whence)
{
int code;
- PerlIO_debug(__FUNCTION__ " f=%p i=%ld+%d\n",f,(long)f->posn,(f->ptr-f->buf));
code = PerlIO_flush(f);
if (code == 0)
{
f->flags &= ~PERLIO_F_EOF;
f->posn = PerlLIO_lseek(f->fd,offset,whence);
- PerlIO_debug(__FUNCTION__ " f=%p o=%ld w=%d p=%ld\n",
- f,(long)offset,whence,(long)f->posn);
if (f->posn == (Off_t) -1)
{
f->posn = 0;