From: Ilya Zakharevich Date: Mon, 2 Jul 2001 06:21:17 +0000 (-0400) Subject: OS/2 cwd X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f5f423e4590905c45492eda1312cb2f76a6ef9a7;p=p5sagit%2Fp5-mst-13.2.git OS/2 cwd Message-ID: <20010702062117.A1401@math.ohio-state.edu> p4raw-id: //depot/perl@11084 --- diff --git a/lib/Cwd.pm b/lib/Cwd.pm index 27a3105..632931b 100644 --- a/lib/Cwd.pm +++ b/lib/Cwd.pm @@ -85,6 +85,25 @@ use base qw/ Exporter /; our @EXPORT = qw(cwd getcwd fastcwd fastgetcwd); our @EXPORT_OK = qw(chdir abs_path fast_abs_path realpath fast_realpath); +# sys_cwd may keep the builtin command + +# All the functionality of this module may provided by builtins, +# there is no sense to process the rest of the file. +# The best choice may be to have this in BEGIN, but how to return from BEGIN? + +if ($^O eq 'os2' && defined &sys_cwd && defined &sys_abspath) { + local $^W = 0; + *cwd = \&sys_cwd; + *getcwd = \&cwd; + *fastgetcwd = \&cwd; + *fastcwd = \&cwd; + *abs_path = \&sys_abspath; + *fast_abs_path = \&abs_path; + *realpath = \&abs_path; + *fast_realpath = \&abs_path; + return 1; +} + eval { require XSLoader; XSLoader::load('Cwd'); diff --git a/lib/File/Find/taint.t b/lib/File/Find/taint.t index f640ef7..e4a292b 100644 --- a/lib/File/Find/taint.t +++ b/lib/File/Find/taint.t @@ -44,7 +44,7 @@ use File::Spec; use Cwd; -my $NonTaintedCwd = $^O eq 'MSWin32' || $^O eq 'cygwin'; +my $NonTaintedCwd = $^O eq 'MSWin32' || $^O eq 'cygwin' || $^O eq 'os2'; cleanup(); diff --git a/lib/FindBin.pm b/lib/FindBin.pm index 5d4c575..91958a8 100644 --- a/lib/FindBin.pm +++ b/lib/FindBin.pm @@ -107,15 +107,15 @@ BEGIN } else { - my $IsWin32 = $^O eq 'MSWin32'; - unless(($script =~ m#/# || ($IsWin32 && $script =~ m#\\#)) + my $doshish = ($^O eq 'MSWin32' or $^O eq 'os2'); + unless(($script =~ m#/# || ($dosish && $script =~ m#\\#)) && -f $script) { my $dir; foreach $dir (File::Spec->path) { my $scr = File::Spec->catfile($dir, $script); - if(-r $scr && (!$IsWin32 || -x _)) + if(-r $scr && (!$dosish || -x _)) { $script = $scr; diff --git a/os2/os2.c b/os2/os2.c index 03c06ed..d7d208e 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); }