Re: [perl #18872] File::Basename example misleading
[p5sagit/p5-mst-13.2.git] / perlio.c
index a9228b4..9cb12d0 100644 (file)
--- a/perlio.c
+++ b/perlio.c
@@ -2795,7 +2795,7 @@ PerlIOStdio_close(pTHX_ PerlIO *f)
         int fd = fileno(stdio);
        int socksfd = 0;
        int invalidate = 0;
-       IV result;
+       IV result = 0;
        int saveerr = 0;
        int dupfd = 0;
 #ifdef SOCKS5_VERSION_NAME
@@ -2830,6 +2830,7 @@ PerlIOStdio_close(pTHX_ PerlIO *f)
               Use Sarathy's trick from maint-5.6 to invalidate the 
               fileno slot of the FILE * 
            */ 
+           result = PerlIO_flush(f);
            saveerr = errno;
            if (!(invalidate = PerlIOStdio_invalidate_fileno(aTHX_ stdio))) {
                dupfd = PerlLIO_dup(fd);
@@ -2860,20 +2861,26 @@ PerlIOStdio_read(pTHX_ PerlIO *f, void *vbuf, Size_t count)
 {
     FILE *s = PerlIOSelf(f, PerlIOStdio)->stdio;
     SSize_t got = 0;
-    if (count == 1) {
-       STDCHAR *buf = (STDCHAR *) vbuf;
-       /*
-        * Perl is expecting PerlIO_getc() to fill the buffer Linux's
-        * stdio does not do that for fread()
-        */
-       int ch = PerlSIO_fgetc(s);
-       if (ch != EOF) {
-           *buf = ch;
-           got = 1;
+    for (;;) {
+       if (count == 1) {
+           STDCHAR *buf = (STDCHAR *) vbuf;
+           /*
+            * Perl is expecting PerlIO_getc() to fill the buffer Linux's
+            * stdio does not do that for fread()
+            */
+           int ch = PerlSIO_fgetc(s);
+           if (ch != EOF) {
+               *buf = ch;
+               got = 1;
+           }
        }
+       else
+           got = PerlSIO_fread(vbuf, 1, count, s);
+       if (got || errno != EINTR)
+           break;
+       PERL_ASYNC_CHECK();
+       errno = 0;      /* just in case */
     }
-    else
-       got = PerlSIO_fread(vbuf, 1, count, s);
     return got;
 }
 
@@ -2938,8 +2945,16 @@ PerlIOStdio_unread(pTHX_ PerlIO *f, const void *vbuf, Size_t count)
 SSize_t
 PerlIOStdio_write(pTHX_ PerlIO *f, const void *vbuf, Size_t count)
 {
-    return PerlSIO_fwrite(vbuf, 1, count,
-                         PerlIOSelf(f, PerlIOStdio)->stdio);
+    SSize_t got;
+    for (;;) {
+       got = PerlSIO_fwrite(vbuf, 1, count,
+                             PerlIOSelf(f, PerlIOStdio)->stdio);
+       if (got || errno != EINTR)
+           break;
+       PERL_ASYNC_CHECK();
+       errno = 0;      /* just in case */
+    }
+    return got;
 }
 
 IV