summaryrefslogtreecommitdiff
path: root/pp_sys.c
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2002-04-07 14:25:28 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2002-04-07 14:25:28 +0000
commitdd36d13c89140c2d9d7954b9f1de583003154c13 (patch)
treeadaef7a5e5beeb3683ba8880a94fc181ad7f00d4 /pp_sys.c
parent525c8498a83d993a86ed1c5080d595040c6663f5 (diff)
downloadperl-dd36d13c89140c2d9d7954b9f1de583003154c13.tar.gz
There was no nice way of getting in UTF-8 filenames:
now one can use in the (new) three-arg form of readdir() and in File::Glob import a ":utf8" to transparently accept the filenames as Unicode. Note that only :utf8 is supported, not fancier stuff like :encoding(foobar) p4raw-id: //depot/perl@15776
Diffstat (limited to 'pp_sys.c')
-rw-r--r--pp_sys.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/pp_sys.c b/pp_sys.c
index 6ed8e0a350..ea9a6a53b8 100644
--- 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)
+ sv_utf8_upgrade(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;