FAQ sync. (Ignoring the few URL differences for now.)
[p5sagit/p5-mst-13.2.git] / pp_sys.c
index 827d8f6..aa8fb77 100644 (file)
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -3747,17 +3747,39 @@ PP(pp_open_dir)
     dSP;
     STRLEN n_a;
     char *dirname = POPpx;
-    GV *gv = (GV*)POPs;
-    register IO *io = GvIOn(gv);
+    char *dscp = NULL;
+    GV *gv;
+    register IO *io;
+    bool want_utf8 = FALSE;
+
+    if (MAXARG == 3)
+        dscp = POPpx;
+
+    gv = (GV*)POPs;
+    io = GvIOn(gv);
 
     if (!io)
        goto nope;
 
+    if (dscp) {
+        if (*dscp == ':') {
+             if (strnEQ(dscp + 1, "utf8", 4))
+                 want_utf8 = TRUE;
+             else
+                  Perl_croak(aTHX_ "Unknown discipline '%s'", dscp);
+        }
+        else
+             Perl_croak(aTHX_ "Unknown discipline '%s'", dscp);
+    }
+
     if (IoDIRP(io))
        PerlDir_close(IoDIRP(io));
     if (!(IoDIRP(io) = PerlDir_open(dirname)))
        goto nope;
 
+    if (want_utf8)
+        IoFLAGS(io) |= IOf_DIR_UTF8;
+
     RETPUSHYES;
 nope:
     if (!errno)
@@ -3795,6 +3817,8 @@ PP(pp_readdir)
            if (!(IoFLAGS(io) & IOf_UNTAINT))
                SvTAINTED_on(sv);
 #endif
+           if (IoFLAGS(io) & IOf_DIR_UTF8 && !IN_BYTES)
+               SvUTF8_on(sv);
            XPUSHs(sv_2mortal(sv));
        }
     }
@@ -3810,6 +3834,8 @@ PP(pp_readdir)
        if (!(IoFLAGS(io) & IOf_UNTAINT))
            SvTAINTED_on(sv);
 #endif
+       if (IoFLAGS(io) & IOf_DIR_UTF8)
+           sv_utf8_upgrade(sv);
        XPUSHs(sv_2mortal(sv));
     }
     RETURN;
@@ -5430,12 +5456,22 @@ PP(pp_ggrent)
        PUSHs(sv = sv_mortalcopy(&PL_sv_no));
        sv_setiv(sv, (IV)grent->gr_gid);
 
+#if !(defined(_CRAYMPP) && defined(USE_REENTRANT_API))
        PUSHs(sv = sv_mortalcopy(&PL_sv_no));
+       /* In UNICOS/mk (_CRAYMPP) the multithreading
+        * versions (getgrnam_r, getgrgid_r)
+        * seem to return an illegal pointer
+        * as the group members list, gr_mem.
+        * getgrent() doesn't even have a _r version
+        * but the gr_mem is poisonous anyway.
+        * So yes, you cannot get the list of group
+        * members if building multithreaded in UNICOS/mk. */
        for (elem = grent->gr_mem; elem && *elem; elem++) {
            sv_catpv(sv, *elem);
            if (elem[1])
                sv_catpvn(sv, " ", 1);
        }
+#endif
     }
 
     RETURN;