This is probably a wrong fix for
authorJarkko Hietaniemi <jhi@iki.fi>
Sat, 30 Aug 2003 18:38:05 +0000 (18:38 +0000)
committerJarkko Hietaniemi <jhi@iki.fi>
Sat, 30 Aug 2003 18:38:05 +0000 (18:38 +0000)
[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

perlio.c
t/io/tell.t

index 4de214d..84c1f79 100644 (file)
--- 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)
 {
index fa5690d..fa9d809 100755 (executable)
@@ -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;