summaryrefslogtreecommitdiff
path: root/os2/os2.c
diff options
context:
space:
mode:
Diffstat (limited to 'os2/os2.c')
-rw-r--r--os2/os2.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/os2/os2.c b/os2/os2.c
index 03c06edd73..d7d208e83b 100644
--- a/os2/os2.c
+++ b/os2/os2.c
@@ -1971,9 +1971,11 @@ XS(XS_Cwd_sys_abspath)
{
STRLEN n_a;
char * path = (char *)SvPV(ST(0),n_a);
- char * dir;
+ char * dir, *s, *t, *e;
char p[MAXPATHLEN];
char * RETVAL;
+ int l;
+ SV *sv;
if (items < 2)
dir = NULL;
@@ -2063,8 +2065,26 @@ XS(XS_Cwd_sys_abspath)
done:
}
}
+ if (!RETVAL)
+ XSRETURN_EMPTY;
+ /* Backslashes are already converted to slashes. */
+ /* Remove trailing slashes */
+ l = strlen(RETVAL);
+ while (l > 0 && RETVAL[l-1] == '/')
+ l--;
ST(0) = sv_newmortal();
- sv_setpv((SV*)ST(0), RETVAL);
+ sv_setpvn( sv = (SV*)ST(0), RETVAL, l);
+ /* Remove duplicate slashes */
+ s = t = 1 + SvPV_force(sv, n_a);
+ e = SvEND(sv);
+ while (s < e) {
+ if (s[0] == t[-1] && s[0] == '/')
+ s++; /* Skip duplicate / */
+ else
+ *t++ = *s++;
+ }
+ *s = 0;
+ SvCUR_set(sv, s - SvPVX(sv));
}
XSRETURN(1);
}