Also the lib/Thread.pm itself needs to be ignored if
[p5sagit/p5-mst-13.2.git] / pp_sys.c
index c1857ae..283dbc1 100644 (file)
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -1,6 +1,6 @@
 /*    pp_sys.c
  *
- *    Copyright (c) 1991-2000, Larry Wall
+ *    Copyright (c) 1991-2001, Larry Wall
  *
  *    You may distribute under the terms of either the GNU General Public
  *    License or the Artistic License, as specified in the README file.
@@ -492,7 +492,9 @@ PP(pp_die)
 
 PP(pp_open)
 {
-    djSP; dTARGET;
+    djSP;
+    dMARK; dORIGMARK;
+    dTARGET;
     GV *gv;
     SV *sv;
     SV *name = Nullsv;
@@ -500,29 +502,19 @@ PP(pp_open)
     char *tmps;
     STRLEN len;
     MAGIC *mg;
+    bool  ok;
 
-    if (MAXARG > 2) {
-       name = POPs;
-       have_name = 1;
-    }
-    if (MAXARG > 1)
-       sv = POPs;
-    if (!isGV(TOPs))
-       DIE(aTHX_ PL_no_usym, "filehandle");
-    if (MAXARG <= 1)
-       sv = GvSV(TOPs);
-    gv = (GV*)POPs;
+    gv = (GV *)*++MARK;
     if (!isGV(gv))
        DIE(aTHX_ PL_no_usym, "filehandle");
     if (GvIOp(gv))
        IoFLAGS(GvIOp(gv)) &= ~IOf_UNTAINT;
 
     if ((mg = SvTIED_mg((SV*)gv, 'q'))) {
-       PUSHMARK(SP);
-       XPUSHs(SvTIED_obj((SV*)gv, mg));
-       XPUSHs(sv);
-       if (have_name)
-           XPUSHs(name);
+       /* Method's args are same as ours ... */
+       /* ... except handle is replaced by the object */
+       *MARK-- = SvTIED_obj((SV*)gv, mg);
+       PUSHMARK(MARK);
        PUTBACK;
        ENTER;
        call_method("OPEN", G_SCALAR);
@@ -531,8 +523,17 @@ PP(pp_open)
        RETURN;
     }
 
+    if (MARK < SP) {
+       sv = *++MARK;
+    }
+    else {
+       sv = GvSV(gv);
+    }
+
     tmps = SvPV(sv, len);
-    if (do_open9(gv, tmps, len, FALSE, O_RDONLY, 0, Nullfp, name, have_name))
+    ok = do_openn(gv, tmps, len, FALSE, O_RDONLY, 0, Nullfp, MARK+1, (SP-MARK));
+    SP = ORIGMARK;
+    if (ok)
        PUSHi( (I32)PL_forkprocess );
     else if (PL_forkprocess == 0)              /* we are a new child */
        PUSHi(0);
@@ -1236,6 +1237,8 @@ PP(pp_leavewrite)
 
     DEBUG_f(PerlIO_printf(Perl_debug_log, "left=%ld, todo=%ld\n",
          (long)IoLINES_LEFT(io), (long)FmLINES(PL_formtarget)));
+    if (!io || !ofp)
+       goto forget_top;
     if (IoLINES_LEFT(io) < FmLINES(PL_formtarget) &&
        PL_formtarget != PL_toptarget)
     {
@@ -1356,6 +1359,7 @@ PP(pp_leavewrite)
            PUSHs(&PL_sv_yes);
        }
     }
+bad_ofp:
     PL_formtarget = PL_bodytarget;
     PUTBACK;
     return pop_return();
@@ -3275,12 +3279,12 @@ PP(pp_fttext)
                continue;
 #endif
            /* utf8 characters don't count as odd */
-           if (*s & 0x40) {
+           if (UTF8_IS_START(*s)) {
                int ulen = UTF8SKIP(s);
                if (ulen < len - i) {
                    int j;
                    for (j = 1; j < ulen; j++) {
-                       if ((s[j] & 0xc0) != 0x80)
+                       if (!UTF8_IS_CONTINUATION(s[j]))
                            goto not_utf8;
                    }
                    --ulen;     /* loop does extra increment */
@@ -3585,15 +3589,31 @@ PP(pp_mkdir)
 #ifndef HAS_MKDIR
     int oldumask;
 #endif
-    STRLEN n_a;
+    STRLEN len;
     char *tmps;
+    bool copy = FALSE;
 
     if (MAXARG > 1)
        mode = POPi;
     else
        mode = 0777;
 
-    tmps = SvPV(TOPs, n_a);
+    tmps = SvPV(TOPs, len);
+    /* Different operating and file systems take differently to
+     * trailing slashes.  According to POSIX 1003.1 1996 Edition
+     * any number of trailing slashes should be allowed.
+     * Thusly we snip them away so that even non-conforming
+     * systems are happy. */
+    /* We should probably do this "filtering" for all
+     * the functions that expect (potentially) directory names:
+     * -d, chdir(), chmod(), chown(), chroot(), fcntl()?,
+     * (mkdir()), opendir(), rename(), rmdir(), stat(). --jhi */
+    if (len > 1 && tmps[len-1] == '/') {
+       while (tmps[len] == '/' && len > 1)
+           len--;
+       tmps = savepvn(tmps, len);
+       copy = TRUE;
+    }
 
     TAINT_PROPER("mkdir");
 #ifdef HAS_MKDIR
@@ -3604,6 +3624,8 @@ PP(pp_mkdir)
     PerlLIO_umask(oldumask);
     PerlLIO_chmod(tmps, (mode & ~oldumask) & 0777);
 #endif
+    if (copy)
+       Safefree(tmps);
     RETURN;
 }