perl 5.003_01: t/lib/filehand.t
[p5sagit/p5-mst-13.2.git] / doio.c
diff --git a/doio.c b/doio.c
index f20d9f7..575427a 100644 (file)
--- a/doio.c
+++ b/doio.c
@@ -192,9 +192,10 @@ FILE *supplied_fp;
                    }
                    if (dodup)
                        fd = dup(fd);
-                   if (!(fp = fdopen(fd,mode)))
+                   if (!(fp = fdopen(fd,mode))) {
                        if (dodup)
                            close(fd);
+                       }
                }
            }
            else {
@@ -278,7 +279,7 @@ FILE *supplied_fp;
     if (saveifp) {             /* must use old fp? */
        fd = fileno(saveifp);
        if (saveofp) {
-           fflush(saveofp);            /* emulate fclose() */
+           Fflush(saveofp);            /* emulate fclose() */
            if (saveofp != saveifp) {   /* was a socket? */
                fclose(saveofp);
                if (fd > 2)
@@ -344,7 +345,7 @@ register GV *gv;
     if (!argvoutgv)
        argvoutgv = gv_fetchpv("ARGVOUT",TRUE,SVt_PVIO);
     if (filemode & (S_ISUID|S_ISGID)) {
-       fflush(IoIFP(GvIOn(argvoutgv)));  /* chmod must follow last write */
+       Fflush(IoIFP(GvIOn(argvoutgv)));  /* chmod must follow last write */
 #ifdef HAS_FCHMOD
        (void)fchmod(lastfd,filemode);
 #else
@@ -407,7 +408,7 @@ register GV *gv;
                    do_close(gv,FALSE);
                    (void)unlink(SvPVX(sv));
                    (void)rename(oldname,SvPVX(sv));
-                   do_open(gv,SvPVX(sv),SvCUR(GvSV(gv)),FALSE,0,0,Nullfp);
+                   do_open(gv,SvPVX(sv),SvCUR(sv),FALSE,0,0,Nullfp);
 #endif /* MSDOS */
 #else
                    (void)UNLINK(SvPVX(sv));
@@ -520,18 +521,18 @@ badexit:
 }
 #endif
 
+/* explicit renamed to avoid C++ conflict    -- kja */
 bool
 #ifndef CAN_PROTOTYPE
-do_close(gv,explicit)
+do_close(gv,not_implicit)
 GV *gv;
-bool explicit;
+bool not_implicit;
 #else
-do_close(GV *gv, bool explicit)
+do_close(GV *gv, bool not_implicit)
 #endif /* CAN_PROTOTYPE */
 {
-    bool retval = FALSE;
-    register IO *io;
-    int status;
+    bool retval;
+    IO *io;
 
     if (!gv)
        gv = argvgv;
@@ -541,10 +542,27 @@ do_close(GV *gv, bool explicit)
     }
     io = GvIO(gv);
     if (!io) {         /* never opened */
-       if (dowarn && explicit)
+       if (dowarn && not_implicit)
            warn("Close on unopened file <%s>",GvENAME(gv));
        return FALSE;
     }
+    retval = io_close(io);
+    if (not_implicit) {
+       IoLINES(io) = 0;
+       IoPAGE(io) = 0;
+       IoLINES_LEFT(io) = IoPAGE_LEN(io);
+    }
+    IoTYPE(io) = ' ';
+    return retval;
+}
+
+bool
+io_close(io)
+IO* io;
+{
+    bool retval = FALSE;
+    int status;
+
     if (IoIFP(io)) {
        if (IoTYPE(io) == '|') {
            status = my_pclose(IoIFP(io));
@@ -563,12 +581,7 @@ do_close(GV *gv, bool explicit)
        }
        IoOFP(io) = IoIFP(io) = Nullfp;
     }
-    if (explicit) {
-       IoLINES(io) = 0;
-       IoPAGE(io) = 0;
-       IoLINES_LEFT(io) = IoPAGE_LEN(io);
-    }
-    IoTYPE(io) = ' ';
+
     return retval;
 }
 
@@ -670,7 +683,7 @@ nuts:
        /* code courtesy of William Kucharski */
 #define HAS_CHSIZE
 
-I32 chsize(fd, length)
+I32 my_chsize(fd, length)
 I32 fd;                        /* file descriptor */
 Off_t length;          /* length to set file to */
 {
@@ -1001,7 +1014,7 @@ char *cmd;
                break;
            }
          doshell:
-           execl("/bin/sh","sh","-c",cmd,(char*)0);
+           execl(SH_PATH, "sh", "-c", cmd, (char*)0);
            return FALSE;
        }
     }
@@ -1177,8 +1190,13 @@ register SV **sp;
 #endif
 
            Zero(&utbuf, sizeof utbuf, char);
+#ifdef BIG_TIME
+           utbuf.actime = (Time_t)SvNVx(*++mark);    /* time accessed */
+           utbuf.modtime = (Time_t)SvNVx(*++mark);    /* time modified */
+#else
            utbuf.actime = SvIVx(*++mark);    /* time accessed */
            utbuf.modtime = SvIVx(*++mark);    /* time modified */
+#endif
            tot = sp - mark;
            while (++mark <= sp) {
                if (utime(SvPVx(*mark, na),&utbuf))