From: Jarkko Hietaniemi Date: Sat, 30 Aug 2003 18:38:05 +0000 (+0000) Subject: This is probably a wrong fix for X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c2fcde81f9cb1a632422e27a9e967bc087d75ae7;p=p5sagit%2Fp5-mst-13.2.git This is probably a wrong fix for [perl #23645] tell with perlio on appended files but maybe this gets NI-S agitated enough to present the correct fix :-) p4raw-id: //depot/perl@20956 --- diff --git a/perlio.c b/perlio.c index 4de214d..84c1f79 100644 --- a/perlio.c +++ b/perlio.c @@ -2375,6 +2375,28 @@ PerlIOUnix_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab) return code; } +IV +PerlIOUnix_seek(pTHX_ PerlIO *f, Off_t offset, int whence) +{ + int fd = PerlIOSelf(f, PerlIOUnix)->fd; + Off_t new; + if (PerlIOBase(f)->flags & PERLIO_F_NOTREG) { +#ifdef ESPIPE + SETERRNO(ESPIPE, LIB_INVARG); +#else + SETERRNO(EINVAL, LIB_INVARG); +#endif + return -1; + } + new = PerlLIO_lseek(fd, offset, whence); + if (new == (Off_t) - 1) + { + return -1; + } + PerlIOBase(f)->flags &= ~PERLIO_F_EOF; + return 0; +} + PerlIO * PerlIOUnix_open(pTHX_ PerlIO_funcs *self, PerlIO_list_t *layers, IV n, const char *mode, int fd, int imode, @@ -2409,6 +2431,8 @@ PerlIOUnix_open(pTHX_ PerlIO_funcs *self, PerlIO_list_t *layers, } PerlIOUnix_setfd(aTHX_ f, fd, imode); PerlIOBase(f)->flags |= PERLIO_F_OPEN; + if (*mode == IoTYPE_APPEND) + PerlIOUnix_seek(aTHX_ f, 0, SEEK_END); return f; } else { @@ -2485,28 +2509,6 @@ PerlIOUnix_write(pTHX_ PerlIO *f, const void *vbuf, Size_t count) } } -IV -PerlIOUnix_seek(pTHX_ PerlIO *f, Off_t offset, int whence) -{ - int fd = PerlIOSelf(f, PerlIOUnix)->fd; - Off_t new; - if (PerlIOBase(f)->flags & PERLIO_F_NOTREG) { -#ifdef ESPIPE - SETERRNO(ESPIPE, LIB_INVARG); -#else - SETERRNO(EINVAL, LIB_INVARG); -#endif - return -1; - } - new = PerlLIO_lseek(fd, offset, whence); - if (new == (Off_t) - 1) - { - return -1; - } - PerlIOBase(f)->flags &= ~PERLIO_F_EOF; - return 0; -} - Off_t PerlIOUnix_tell(pTHX_ PerlIO *f) { diff --git a/t/io/tell.t b/t/io/tell.t index fa5690d..fa9d809 100755 --- a/t/io/tell.t +++ b/t/io/tell.t @@ -7,7 +7,7 @@ BEGIN { @INC = '../lib'; } -print "1..27\n"; +print "1..28\n"; $TST = 'tst'; @@ -143,4 +143,12 @@ if (tell($tst) == 15 || close($tst); +open($tst,">$written") || die "Cannot open $written:$!"; +print $tst "foobar"; +close $tst; +open($tst,">>$written") || die "Cannot open $written:$!"; + +if (tell($tst) == 6) +{ print "ok 28\n"; } else { print "not ok 28\n"; } +close $tst;