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');
use Cwd;
-my $NonTaintedCwd = $^O eq 'MSWin32' || $^O eq 'cygwin';
+my $NonTaintedCwd = $^O eq 'MSWin32' || $^O eq 'cygwin' || $^O eq 'os2';
cleanup();
}
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;
{
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;
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);
}