(perl #133951) add Internals::getcwd
authorTony Cook <tony@develop-help.com>
Mon, 25 Mar 2019 05:48:40 +0000 (16:48 +1100)
committerTony Cook <tony@develop-help.com>
Sun, 14 Apr 2019 23:26:29 +0000 (09:26 +1000)
MANIFEST
t/io/getcwd.t [new file with mode: 0644]
universal.c

index c219881..07e9f6c 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -5425,6 +5425,7 @@ t/io/errno.t                      See if $! is correctly set
 t/io/errnosig.t                        Test case for restoration $! when leaving signal handlers
 t/io/fflush.t                  See if auto-flush on fork/exec/system/qx works
 t/io/fs.t                      See if directory manipulations work
+t/io/getcwd.t                  See if Internals::getcwd is sane
 t/io/inplace.t                 See if inplace editing works
 t/io/iofile.t                  See if we can load IO::File on demand
 t/io/iprefix.t                 See if inplace editing works with prefixes
diff --git a/t/io/getcwd.t b/t/io/getcwd.t
new file mode 100644 (file)
index 0000000..f3ad58b
--- /dev/null
@@ -0,0 +1,22 @@
+#!./perl -w
+
+BEGIN {
+    chdir 't' if -d 't';
+    require "./test.pl";
+    set_up_inc('../lib');
+}
+
+use Config;
+
+$Config{d_getcwd}
+  or plan skip_all => "no getcwd";
+
+my $cwd = Internals::getcwd();
+ok(!defined $cwd || $cwd ne "",
+   "Internals::getcwd() returned a reasonable result");
+
+if (defined $cwd) {
+    ok(-d $cwd, "check a success result is a directory");
+}
+
+done_testing();
index c1b5dd4..66eafc5 100644 (file)
@@ -986,6 +986,25 @@ XS(XS_re_regexp_pattern)
     NOT_REACHED; /* NOTREACHED */
 }
 
+#ifdef HAS_GETCWD
+
+XS(XS_Internals_getcwd)
+{
+    dXSARGS;
+    SV *sv = sv_newmortal();
+
+    if (items != 0)
+        croak_xs_usage(cv, "");
+
+    (void)getcwd_sv(sv);
+
+    SvTAINTED_on(sv);
+    PUSHs(sv);
+    XSRETURN(1);
+}
+
+#endif
+
 #include "vutil.h"
 #include "vxs.inc"
 
@@ -1020,6 +1039,9 @@ static const struct xsub_details these_details[] = {
     {"re::regnames", XS_re_regnames, ";$"},
     {"re::regnames_count", XS_re_regnames_count, ""},
     {"re::regexp_pattern", XS_re_regexp_pattern, "$"},
+#ifdef HAS_GETCWD
+    {"Internals::getcwd", XS_Internals_getcwd, ""},
+#endif
 };
 
 STATIC OP*