diff options
author | Nick Ing-Simmons <nik@tiuk.ti.com> | 2000-12-07 21:43:32 +0000 |
---|---|---|
committer | Nick Ing-Simmons <nik@tiuk.ti.com> | 2000-12-07 21:43:32 +0000 |
commit | 766a733e849204725c27391cf2992d649af4aba6 (patch) | |
tree | 7935daf06a9e30818e169d984bb68417c31b3745 /perlio.c | |
parent | be696b0a6b61315b71a751e7291be8d8a9066650 (diff) | |
download | perl-766a733e849204725c27391cf2992d649af4aba6.tar.gz |
Change PerlIO_(get|set)pos to take SV *
Should fix, OS/2, VMS, (sfio??)
p4raw-id: //depot/perlio@8025
Diffstat (limited to 'perlio.c')
-rw-r--r-- | perlio.c | 77 |
1 files changed, 50 insertions, 27 deletions
@@ -239,7 +239,7 @@ PerlIO_allocate(pTHX) if (!f) { return NULL; - } + } *last = f; return f+1; } @@ -318,7 +318,7 @@ PerlIO_find_layer(const char *name, STRLEN len) dTHX; SV **svp; SV *sv; - if (len <= 0) + if ((SSize_t) len <= 0) len = strlen(name); svp = hv_fetch(PerlIO_layer_hv,name,len,0); if (svp && (sv = *svp) && SvROK(sv)) @@ -643,7 +643,7 @@ PerlIO_fdupopen(pTHX_ PerlIO *f) Off_t posn = PerlIO_tell(f); PerlIO_seek(new,posn,SEEK_SET); } - return new; + return new; } #undef PerlIO_close @@ -932,7 +932,7 @@ PerlIO_modestr(PerlIO *f,char *buf) { *s++ = '+'; } - } + } else if (flags & PERLIO_F_CANREAD) { *s++ = 'r'; @@ -1298,6 +1298,7 @@ Off_t PerlIOUnix_tell(PerlIO *f) { dTHX; + Off_t posn = PerlLIO_lseek(PerlIOSelf(f,PerlIOUnix)->fd,0,SEEK_CUR); return PerlLIO_lseek(PerlIOSelf(f,PerlIOUnix)->fd,0,SEEK_CUR); } @@ -1367,20 +1368,19 @@ PerlIOStdio_fileno(PerlIO *f) return PerlSIO_fileno(PerlIOSelf(f,PerlIOStdio)->stdio); } -const char * +char * PerlIOStdio_mode(const char *mode,char *tmode) { - const char *ret = mode; + char *ret = tmode; + while (*mode) + { + *tmode++ = *mode++; + } if (O_BINARY != O_TEXT) { - ret = (const char *) tmode; - while (*mode) - { - *tmode++ = *mode++; - } *tmode++ = 'b'; - *tmode = '\0'; } + *tmode = '\0'; return ret; } @@ -3148,47 +3148,70 @@ PerlIO_tmpfile(void) #ifndef HAS_FSETPOS #undef PerlIO_setpos int -PerlIO_setpos(PerlIO *f, const Fpos_t *pos) +PerlIO_setpos(PerlIO *f, SV *pos) { - return PerlIO_seek(f,*pos,0); + dTHX; + if (SvOK(pos)) + { + STRLEN len; + Off_t *posn = (Off_t *) SvPV(pos,len); + if (f && len == sizeof(Off_t)) + return PerlIO_seek(f,*posn,SEEK_SET); + } + errno = EINVAL; + return -1; } #else -#ifndef PERLIO_IS_STDIO #undef PerlIO_setpos int -PerlIO_setpos(PerlIO *f, const Fpos_t *pos) +PerlIO_setpos(PerlIO *f, SV *pos) { + dTHX; + if (SvOK(pos)) + { + STRLEN len; + Fpos_t *fpos = (Fpos_t *) SvPV(pos,len); + if (f && len == sizeof(Fpos_t)) + { #if defined(USE_64_BIT_STDIO) && defined(USE_FSETPOS64) - return fsetpos64(f, pos); + return fsetpos64(f, fpos); #else - return fsetpos(f, pos); + return fsetpos(f, fpos); #endif + } + } + errno = EINVAL; + return -1; } #endif -#endif #ifndef HAS_FGETPOS #undef PerlIO_getpos int -PerlIO_getpos(PerlIO *f, Fpos_t *pos) +PerlIO_getpos(PerlIO *f, SV *pos) { - *pos = PerlIO_tell(f); - return *pos == -1 ? -1 : 0; + dTHX; + Off_t posn = PerlIO_tell(f); + sv_setpvn(pos,(char *)&posn,sizeof(posn)); + return (posn == (Off_t)-1) ? -1 : 0; } #else -#ifndef PERLIO_IS_STDIO #undef PerlIO_getpos int -PerlIO_getpos(PerlIO *f, Fpos_t *pos) +PerlIO_getpos(PerlIO *f, SV *pos) { + dTHX; + Fpos_t fpos; + int code; #if defined(USE_64_BIT_STDIO) && defined(USE_FSETPOS64) - return fgetpos64(f, pos); + code = fgetpos64(f, &fpos); #else - return fgetpos(f, pos); + code = fgetpos(f, &fpos); #endif + sv_setpvn(pos,(char *)&fpos,sizeof(fpos)); + return code; } #endif -#endif #if (defined(PERLIO_IS_STDIO) || !defined(USE_SFIO)) && !defined(HAS_VPRINTF) |