You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
2.0 KiB

  1. From 15f67d146cf1f32504e8a11de3faa2abc0f467cd Mon Sep 17 00:00:00 2001
  2. From: Tony Cook <tony@develop-help.com>
  3. Date: Mon, 25 Mar 2019 16:48:40 +1100
  4. Subject: [PATCH] (perl #133951) add Internals::getcwd
  5. ---
  6. MANIFEST | 1 +
  7. t/io/getcwd.t | 22 ++++++++++++++++++++++
  8. universal.c | 22 ++++++++++++++++++++++
  9. 3 files changed, 45 insertions(+)
  10. create mode 100644 t/io/getcwd.t
  11. --- a/MANIFEST
  12. +++ b/MANIFEST
  13. @@ -5456,6 +5456,7 @@ t/io/errno.t See if $! is correctly se
  14. t/io/errnosig.t Test case for restoration $! when leaving signal handlers
  15. t/io/fflush.t See if auto-flush on fork/exec/system/qx works
  16. t/io/fs.t See if directory manipulations work
  17. +t/io/getcwd.t See if Internals::getcwd is sane
  18. t/io/inplace.t See if inplace editing works
  19. t/io/iofile.t See if we can load IO::File on demand
  20. t/io/iprefix.t See if inplace editing works with prefixes
  21. --- /dev/null
  22. +++ b/t/io/getcwd.t
  23. @@ -0,0 +1,22 @@
  24. +#!./perl -w
  25. +
  26. +BEGIN {
  27. + chdir 't' if -d 't';
  28. + require "./test.pl";
  29. + set_up_inc('../lib');
  30. +}
  31. +
  32. +use Config;
  33. +
  34. +$Config{d_getcwd}
  35. + or plan skip_all => "no getcwd";
  36. +
  37. +my $cwd = Internals::getcwd();
  38. +ok(!defined $cwd || $cwd ne "",
  39. + "Internals::getcwd() returned a reasonable result");
  40. +
  41. +if (defined $cwd) {
  42. + ok(-d $cwd, "check a success result is a directory");
  43. +}
  44. +
  45. +done_testing();
  46. --- a/universal.c
  47. +++ b/universal.c
  48. @@ -986,6 +986,25 @@ XS(XS_re_regexp_pattern)
  49. NOT_REACHED; /* NOTREACHED */
  50. }
  51. +#ifdef HAS_GETCWD
  52. +
  53. +XS(XS_Internals_getcwd)
  54. +{
  55. + dXSARGS;
  56. + SV *sv = sv_newmortal();
  57. +
  58. + if (items != 0)
  59. + croak_xs_usage(cv, "");
  60. +
  61. + (void)getcwd_sv(sv);
  62. +
  63. + SvTAINTED_on(sv);
  64. + PUSHs(sv);
  65. + XSRETURN(1);
  66. +}
  67. +
  68. +#endif
  69. +
  70. #include "vutil.h"
  71. #include "vxs.inc"
  72. @@ -1020,6 +1039,9 @@ static const struct xsub_details details
  73. {"re::regnames", XS_re_regnames, ";$"},
  74. {"re::regnames_count", XS_re_regnames_count, ""},
  75. {"re::regexp_pattern", XS_re_regexp_pattern, "$"},
  76. +#ifdef HAS_GETCWD
  77. + {"Internals::getcwd", XS_Internals_getcwd, ""},
  78. +#endif
  79. };
  80. STATIC OP*