This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
miniperl build fixes for os2 (from Yitzchak Scott-Thoennes
[perl5.git] / doio.c
diff --git a/doio.c b/doio.c
index d3d4d97..c13228a 100644 (file)
--- a/doio.c
+++ b/doio.c
@@ -134,14 +134,14 @@ Perl_do_open9(pTHX_ GV *gv, register char *name, I32 len, int as_raw,
        else
            result = PerlIO_close(IoIFP(io));
        if (result == EOF && fd > PL_maxsysfd)
-           PerlIO_printf(PerlIO_stderr(),
+           PerlIO_printf(Perl_error_log,
                          "Warning: unable to close filehandle %s properly.\n",
                          GvENAME(gv));
        IoOFP(io) = IoIFP(io) = Nullfp;
     }
 
     if (as_raw) {
-#if defined(USE_64_BIT_OFFSETS) && defined(O_LARGEFILE)
+#if defined(USE_64_BIT_RAWIO) && defined(O_LARGEFILE)
        rawmode |= O_LARGEFILE;
 #endif
 
@@ -236,7 +236,7 @@ Perl_do_open9(pTHX_ GV *gv, register char *name, I32 len, int as_raw,
                dTHR;
                name[strlen(name)-1] = '\0' ;
                if (ckWARN(WARN_PIPE))
-                   Perl_warner(aTHX_ WARN_PIPE, "Can't do bidirectional pipe");
+                   Perl_warner(aTHX_ WARN_PIPE, "Can't open bidirectional pipe");
            }
            fp = PerlProc_popen(name,"w");
            writing = 1;
@@ -283,8 +283,17 @@ Perl_do_open9(pTHX_ GV *gv, register char *name, I32 len, int as_raw,
                        }
                        if (IoIFP(thatio)) {
                            PerlIO *fp = IoIFP(thatio);
-                               /* Flush stdio buffer before dup */
+                           /* Flush stdio buffer before dup. --mjd
+                            * Unfortunately SEEK_CURing 0 seems to
+                            * be optimized away on most platforms;
+                            * only Solaris and Linux seem to flush
+                            * on that. --jhi */
                            PerlIO_seek(fp, 0, SEEK_CUR);
+                           /* On the other hand, do all platforms
+                            * take gracefully to flushing a read-only
+                            * filehandle?  Perhaps we should do
+                            * fsetpos(src)+fgetpos(dst)?  --nik */
+                           PerlIO_flush(fp);
                            fd = PerlIO_fileno(fp);
                            if (IoTYPE(thatio) == 's')
                                IoTYPE(io) = 's';
@@ -475,9 +484,18 @@ Perl_nextargv(pTHX_ register GV *gv)
 #endif
     Uid_t fileuid;
     Gid_t filegid;
+    IO *io = GvIOp(gv);
 
     if (!PL_argvoutgv)
        PL_argvoutgv = gv_fetchpv("ARGVOUT",TRUE,SVt_PVIO);
+    if (io && (IoFLAGS(io) & IOf_ARGV) && (IoFLAGS(io) & IOf_START)) {
+       IoFLAGS(io) &= ~IOf_START;
+       if (PL_inplace) {
+           if (!PL_argvout_stack)
+               PL_argvout_stack = newAV();
+           av_push(PL_argvout_stack, SvREFCNT_inc(PL_defoutgv));
+       }
+    }
     if (PL_filemode & (S_ISUID|S_ISGID)) {
        PerlIO_flush(IoIFP(GvIOn(PL_argvoutgv)));  /* chmod must follow last write */
 #ifdef HAS_FCHMOD
@@ -601,11 +619,12 @@ Perl_nextargv(pTHX_ register GV *gv)
                SETERRNO(0,0);          /* in case sprintf set errno */
 #ifdef VMS
                if (!do_open(PL_argvoutgv,SvPVX(sv),SvCUR(sv),PL_inplace!=0,
-                 O_WRONLY|O_CREAT|O_TRUNC,0,Nullfp)) { 
+                 O_WRONLY|O_CREAT|O_TRUNC,0,Nullfp))
 #else
                if (!do_open(PL_argvoutgv,SvPVX(sv),SvCUR(sv),PL_inplace!=0,
-                            O_WRONLY|O_CREAT|OPEN_EXCL,0666,Nullfp)) {
+                            O_WRONLY|O_CREAT|OPEN_EXCL,0666,Nullfp))
 #endif
+               {
                    if (ckWARN_d(WARN_INPLACE)) 
                        Perl_warner(aTHX_ WARN_INPLACE, "Can't do inplace edit on %s: %s",
                          PL_oldname, Strerror(errno) );
@@ -641,15 +660,25 @@ Perl_nextargv(pTHX_ register GV *gv)
                if (!S_ISREG(PL_statbuf.st_mode))       
                    Perl_warner(aTHX_ WARN_INPLACE,
                                "Can't do inplace edit: %s is not a regular file",
-                               PL_oldname );
+                               PL_oldname);
                else
-                   Perl_warner(aTHX_ WARN_INPLACE, "Can't open %s: %s\n",
+                   Perl_warner(aTHX_ WARN_INPLACE, "Can't open %s: %s",
                                PL_oldname, Strerror(errno));
            }
        }
     }
+    if (io && (IoFLAGS(io) & IOf_ARGV))
+       IoFLAGS(io) |= IOf_START;
     if (PL_inplace) {
        (void)do_close(PL_argvoutgv,FALSE);
+       if (io && (IoFLAGS(io) & IOf_ARGV)
+           && PL_argvout_stack && AvFILLp(PL_argvout_stack) >= 0)
+       {
+           GV *oldout = (GV*)av_pop(PL_argvout_stack);
+           setdefout(oldout);
+           SvREFCNT_dec(oldout);
+           return Nullfp;
+       }
        setdefout(gv_fetchpv("STDOUT",TRUE,SVt_PVIO));
     }
     return Nullfp;
@@ -997,24 +1026,17 @@ Perl_do_print(pTHX_ register SV *sv, PerlIO *fp)
        {
            dTHR;
            if (ckWARN(WARN_UNINITIALIZED))
-               Perl_warner(aTHX_ WARN_UNINITIALIZED, PL_warn_uninit);
+               report_uninit();
        }
        return TRUE;
     case SVt_IV:
        if (SvIOK(sv)) {
            if (SvGMAGICAL(sv))
                mg_get(sv);
-#ifdef IV_IS_QUAD
-           if (SvIsUV(sv))
-               PerlIO_printf(fp, "%" PERL_PRIu64, (UV)SvUVX(sv));
-           else
-               PerlIO_printf(fp, "%" PERL_PRId64, (IV)SvIVX(sv));
-#else
            if (SvIsUV(sv))
-               PerlIO_printf(fp, "%lu", (unsigned long)SvUVX(sv));
+               PerlIO_printf(fp, "%"UVuf, (UV)SvUVX(sv));
            else
-               PerlIO_printf(fp, "%ld", (long)SvIVX(sv));
-#endif
+               PerlIO_printf(fp, "%"IVdf, (IV)SvIVX(sv));
            return !PerlIO_error(fp);
        }
        /* FALL THROUGH */
@@ -1026,7 +1048,8 @@ Perl_do_print(pTHX_ register SV *sv, PerlIO *fp)
      * filesize limit we would need getrlimit().  We could then
      * also transparently raise the limit with setrlimit() --
      * but only until the system hard limit/the filesystem limit,
-     * at which we would get EPERM. --jhi */
+     * at which we would get EPERM.  Note that when using buffered
+     * io the write failure can be delayed until the flush/close. --jhi */
     if (len && (PerlIO_write(fp,tmps,len) == 0 || PerlIO_error(fp)))
        return FALSE;
     return !PerlIO_error(fp);
@@ -1041,7 +1064,7 @@ Perl_my_stat(pTHX)
 
     if (PL_op->op_flags & OPf_REF) {
        EXTEND(SP,1);
-       tmpgv = cGVOP->op_gv;
+       tmpgv = cGVOP_gv;
       do_fstat:
        io = GvIO(tmpgv);
        if (io && IoIFP(io)) {
@@ -1094,7 +1117,7 @@ Perl_my_lstat(pTHX)
     STRLEN n_a;
     if (PL_op->op_flags & OPf_REF) {
        EXTEND(SP,1);
-       if (cGVOP->op_gv == PL_defgv) {
+       if (cGVOP_gv == PL_defgv) {
            if (PL_laststype != OP_LSTAT)
                Perl_croak(aTHX_ "The stat preceding -l _ wasn't an lstat");
            return PL_laststatval;
@@ -1123,6 +1146,9 @@ bool
 Perl_do_aexec5(pTHX_ SV *really, register SV **mark, register SV **sp,
               int fd, int do_report)
 {
+#ifdef MACOS_TRADITIONAL
+    Perl_croak(aTHX_ "exec? I'm not *that* kind of operating system");
+#else
     register char **a;
     char *tmps;
     STRLEN n_a;
@@ -1155,6 +1181,7 @@ Perl_do_aexec5(pTHX_ SV *really, register SV **mark, register SV **sp,
        }
     }
     do_execfree();
+#endif
     return FALSE;
 }
 
@@ -1171,7 +1198,7 @@ Perl_do_execfree(pTHX)
     }
 }
 
-#if !defined(OS2) && !defined(WIN32) && !defined(DJGPP) && !defined(EPOC)
+#if !defined(OS2) && !defined(WIN32) && !defined(DJGPP) && !defined(EPOC) && !defined(MACOS_TRADITIONAL)
 
 bool
 Perl_do_exec(pTHX_ char *cmd)
@@ -1552,6 +1579,10 @@ Perl_cando(pTHX_ Mode_t mode, Uid_t effective, register Stat_t *statbufp)
 bool
 Perl_ingroup(pTHX_ Gid_t testgid, Uid_t effective)
 {
+#ifdef MACOS_TRADITIONAL
+    /* This is simply not correct for AppleShare, but fix it yerself. */
+    return TRUE;
+#else
     if (testgid == (effective ? PL_egid : PL_gid))
        return TRUE;
 #ifdef HAS_GETGROUPS
@@ -1569,6 +1600,7 @@ Perl_ingroup(pTHX_ Gid_t testgid, Uid_t effective)
     }
 #endif
     return FALSE;
+#endif
 }
 
 #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
@@ -1686,7 +1718,7 @@ Perl_do_ipcctl(pTHX_ I32 optype, SV **mark, SV **sp)
     else
     {
        IV i = SvIV(astr);
-       a = (char *)i;          /* ouch */
+       a = INT2PTR(char *,i);          /* ouch */
     }
     SETERRNO(0,0);
     switch (optype)