This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
In Cwd.xs on VMS, don't compile bsd_realpath() at all.
authorNicholas Clark <nick@ccl4.org>
Sat, 18 Jun 2011 13:09:24 +0000 (15:09 +0200)
committerNicholas Clark <nick@ccl4.org>
Wed, 22 Jun 2011 14:53:51 +0000 (16:53 +0200)
On VMS, call Perl_rmsexpand() directly from abs_path(), instead of making
bsd_realpath() a trivial wrapper to Perl_rmsexpand().

Initialise path at the point of declaration, instead of separately. Use
sv_setpv_mg() instead of sv_setpvn() with an explicit strlen(), changing
PUSHTARG to PUSHs(TARG) to avoid setting magic twice.

dist/Cwd/Cwd.xs

index ade4e36..e42a95f 100644 (file)
@@ -55,6 +55,7 @@
 #define MAXSYMLINKS 8
 #endif
 
+#ifndef VMS
 /*
  * char *realpath(const char *path, char resolved[MAXPATHLEN]);
  *
@@ -66,10 +67,6 @@ static
 char *
 bsd_realpath(const char *path, char resolved[MAXPATHLEN])
 {
-#ifdef VMS
-       dTHX;
-       return Perl_rmsexpand(aTHX_ (char*)path, resolved, NULL, 0);
-#else
        char *p, *q, *s;
        size_t left_len, resolved_len;
        unsigned symlinks;
@@ -218,8 +215,8 @@ bsd_realpath(const char *path, char resolved[MAXPATHLEN])
        if (resolved_len > 1 && resolved[resolved_len - 1] == '/')
                resolved[resolved_len - 1] = '\0';
        return (resolved);
-#endif
 }
+#endif
 
 #ifndef SV_CWD_RETURN_UNDEF
 #define SV_CWD_RETURN_UNDEF \
@@ -436,20 +433,24 @@ PROTOTYPE: DISABLE
 PPCODE:
 {
     dXSTARG;
-    char *path;
+    char *const path = pathsv ? SvPV_nolen(pathsv) : (char *)".";
     char buf[MAXPATHLEN];
 
-    path = pathsv ? SvPV_nolen(pathsv) : (char *)".";
-
-    if (bsd_realpath(path, buf)) {
-        sv_setpvn(TARG, buf, strlen(buf));
+    if (
+#ifdef VMS
+       Perl_rmsexpand(aTHX_ path, buf, NULL, 0)
+#else
+       bsd_realpath(path, buf)
+#endif
+    ) {
+       sv_setpv_mg(TARG, buf);
         SvPOK_only(TARG);
        SvTAINTED_on(TARG);
     }
     else
         sv_setsv(TARG, &PL_sv_undef);
 
-    XSprePUSH; PUSHTARG;
+    XSprePUSH; PUSHs(TARG);
 #ifndef INCOMPLETE_TAINTS
     SvTAINTED_on(TARG);
 #endif
@@ -477,7 +478,7 @@ PPCODE:
 
     New(0,dir,MAXPATHLEN,char);
     if (_getdcwd(drive, dir, MAXPATHLEN)) {
-        sv_setpvn(TARG, dir, strlen(dir));
+        sv_setpv_mg(TARG, dir);
         SvPOK_only(TARG);
     }
     else
@@ -485,7 +486,7 @@ PPCODE:
 
     Safefree(dir);
 
-    XSprePUSH; PUSHTARG;
+    XSprePUSH; PUSHs(TARG);
 #ifndef INCOMPLETE_TAINTS
     SvTAINTED_on(TARG);
 #endif