diff options
Diffstat (limited to 'os2/os2.c')
-rw-r--r-- | os2/os2.c | 24 |
1 files changed, 22 insertions, 2 deletions
@@ -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); } |