File Coverage

blib/lib/Cwd.pm
Criterion Covered Total %
statement 0 224 0.0
branch 0 154 0.0
condition 0 71 0.0
subroutine 0 20 0.0
pod 1 4 25.0
total 1 473 0.2


line stmt bran cond sub pod time code
1             package Cwd;
2             use strict;
3             use Exporter;
4             use vars qw(@ISA @EXPORT @EXPORT_OK $VERSION);
5              
6             $VERSION = '3.62';
7             my $xs_version = $VERSION;
8             $VERSION =~ tr/_//d;
9              
10             @ISA = qw/ Exporter /;
11             @EXPORT = qw(cwd getcwd fastcwd fastgetcwd);
12             push @EXPORT, qw(getdcwd) if $^O eq 'MSWin32';
13             @EXPORT_OK = qw(chdir abs_path fast_abs_path realpath fast_realpath);
14              
15             # sys_cwd may keep the builtin command
16              
17             # All the functionality of this module may provided by builtins,
18             # there is no sense to process the rest of the file.
19             # The best choice may be to have this in BEGIN, but how to return from BEGIN?
20              
21             if ($^O eq 'os2') {
22             local $^W = 0;
23              
24             *cwd = defined &sys_cwd ? \&sys_cwd : \&_os2_cwd;
25             *getcwd = \&cwd;
26             *fastgetcwd = \&cwd;
27             *fastcwd = \&cwd;
28              
29             *fast_abs_path = \&sys_abspath if defined &sys_abspath;
30             *abs_path = \&fast_abs_path;
31             *realpath = \&fast_abs_path;
32             *fast_realpath = \&fast_abs_path;
33              
34             return 1;
35             }
36              
37             # Need to look up the feature settings on VMS. The preferred way is to use the
38             # VMS::Feature module, but that may not be available to dual life modules.
39              
40             my $use_vms_feature;
41             BEGIN {
42             if ($^O eq 'VMS') {
43             if (eval { local $SIG{__DIE__}; require VMS::Feature; }) {
44             $use_vms_feature = 1;
45             }
46             }
47             }
48              
49             # Need to look up the UNIX report mode. This may become a dynamic mode
50             # in the future.
51             sub _vms_unix_rpt {
52 0     0     my $unix_rpt;
53 0 0         if ($use_vms_feature) {
54 0           $unix_rpt = VMS::Feature::current("filename_unix_report");
55             } else {
56 0   0       my $env_unix_rpt = $ENV{'DECC$FILENAME_UNIX_REPORT'} || '';
57 0           $unix_rpt = $env_unix_rpt =~ /^[ET1]/i;
58             }
59 0           return $unix_rpt;
60             }
61              
62             # Need to look up the EFS character set mode. This may become a dynamic
63             # mode in the future.
64             sub _vms_efs {
65 0     0     my $efs;
66 0 0         if ($use_vms_feature) {
67 0           $efs = VMS::Feature::current("efs_charset");
68             } else {
69 0   0       my $env_efs = $ENV{'DECC$EFS_CHARSET'} || '';
70 0           $efs = $env_efs =~ /^[ET1]/i;
71             }
72 0           return $efs;
73             }
74              
75              
76             # If loading the XS stuff doesn't work, we can fall back to pure perl
77             if(! defined &getcwd && defined &DynaLoader::boot_DynaLoader) {
78             eval {#eval is questionable since we are handling potential errors like
79             #"Cwd object version 3.48 does not match bootstrap parameter 3.50
80             #at lib/DynaLoader.pm line 216." by having this eval
81             if ( $] >= 5.006 ) {
82             require XSLoader;
83             XSLoader::load( __PACKAGE__, $xs_version);
84             } else {
85             require DynaLoader;
86             push @ISA, 'DynaLoader';
87             __PACKAGE__->bootstrap( $xs_version );
88             }
89             };
90             }
91              
92             # Big nasty table of function aliases
93             my %METHOD_MAP =
94             (
95             VMS =>
96             {
97             cwd => '_vms_cwd',
98             getcwd => '_vms_cwd',
99             fastcwd => '_vms_cwd',
100             fastgetcwd => '_vms_cwd',
101             abs_path => '_vms_abs_path',
102             fast_abs_path => '_vms_abs_path',
103             },
104              
105             MSWin32 =>
106             {
107             # We assume that &_NT_cwd is defined as an XSUB or in the core.
108             cwd => '_NT_cwd',
109             getcwd => '_NT_cwd',
110             fastcwd => '_NT_cwd',
111             fastgetcwd => '_NT_cwd',
112             abs_path => 'fast_abs_path',
113             realpath => 'fast_abs_path',
114             },
115              
116             dos =>
117             {
118             cwd => '_dos_cwd',
119             getcwd => '_dos_cwd',
120             fastgetcwd => '_dos_cwd',
121             fastcwd => '_dos_cwd',
122             abs_path => 'fast_abs_path',
123             },
124              
125             # QNX4. QNX6 has a $os of 'nto'.
126             qnx =>
127             {
128             cwd => '_qnx_cwd',
129             getcwd => '_qnx_cwd',
130             fastgetcwd => '_qnx_cwd',
131             fastcwd => '_qnx_cwd',
132             abs_path => '_qnx_abs_path',
133             fast_abs_path => '_qnx_abs_path',
134             },
135              
136             cygwin =>
137             {
138             getcwd => 'cwd',
139             fastgetcwd => 'cwd',
140             fastcwd => 'cwd',
141             abs_path => 'fast_abs_path',
142             realpath => 'fast_abs_path',
143             },
144              
145             epoc =>
146             {
147             cwd => '_epoc_cwd',
148             getcwd => '_epoc_cwd',
149             fastgetcwd => '_epoc_cwd',
150             fastcwd => '_epoc_cwd',
151             abs_path => 'fast_abs_path',
152             },
153              
154             MacOS =>
155             {
156             getcwd => 'cwd',
157             fastgetcwd => 'cwd',
158             fastcwd => 'cwd',
159             abs_path => 'fast_abs_path',
160             },
161              
162             amigaos =>
163             {
164             getcwd => '_backtick_pwd',
165             fastgetcwd => '_backtick_pwd',
166             fastcwd => '_backtick_pwd',
167             abs_path => 'fast_abs_path',
168             }
169             );
170              
171             $METHOD_MAP{NT} = $METHOD_MAP{MSWin32};
172              
173              
174             # Find the pwd command in the expected locations. We assume these
175             # are safe. This prevents _backtick_pwd() consulting $ENV{PATH}
176             # so everything works under taint mode.
177             my $pwd_cmd;
178             if($^O ne 'MSWin32') {
179             foreach my $try ('/bin/pwd',
180             '/usr/bin/pwd',
181             '/QOpenSys/bin/pwd', # OS/400 PASE.
182             ) {
183             if( -x $try ) {
184             $pwd_cmd = $try;
185             last;
186             }
187             }
188             }
189              
190             # Android has a built-in pwd. Using $pwd_cmd will DTRT if
191             # this perl was compiled with -Dd_useshellcmds, which is the
192             # default for Android, but the block below is needed for the
193             # miniperl running on the host when cross-compiling, and
194             # potentially for native builds with -Ud_useshellcmds.
195             if ($^O =~ /android/) {
196             # If targetsh is executable, then we're either a full
197             # perl, or a miniperl for a native build.
198             if (-x $Config::Config{targetsh}) {
199             $pwd_cmd = "$Config::Config{targetsh} -c pwd"
200             }
201             else {
202             my $sh = $Config::Config{sh} || (-x '/system/bin/sh' ? '/system/bin/sh' : 'sh');
203             $pwd_cmd = "$sh -c pwd"
204             }
205             }
206              
207             my $found_pwd_cmd = defined($pwd_cmd);
208             unless ($pwd_cmd) {
209             # Isn't this wrong? _backtick_pwd() will fail if someone has
210             # pwd in their path but it is not /bin/pwd or /usr/bin/pwd?
211             # See [perl #16774]. --jhi
212             $pwd_cmd = 'pwd';
213             }
214              
215             # Lazy-load Carp
216 0     0     sub _carp { require Carp; Carp::carp(@_) }
  0            
217 0     0     sub _croak { require Carp; Carp::croak(@_) }
  0            
218              
219             # The 'natural and safe form' for UNIX (pwd may be setuid root)
220             sub _backtick_pwd {
221              
222             # Localize %ENV entries in a way that won't create new hash keys.
223             # Under AmigaOS we don't want to localize as it stops perl from
224             # finding 'sh' in the PATH.
225 0 0   0     my @localize = grep exists $ENV{$_}, qw(PATH IFS CDPATH ENV BASH_ENV) if $^O ne "amigaos";
226 0 0         local @ENV{@localize} if @localize;
227            
228 0           my $cwd = `$pwd_cmd`;
229             # Belt-and-suspenders in case someone said "undef $/".
230 0           local $/ = "\n";
231             # `pwd` may fail e.g. if the disk is full
232 0 0         chomp($cwd) if defined $cwd;
233 0           $cwd;
234             }
235              
236             # Since some ports may predefine cwd internally (e.g., NT)
237             # we take care not to override an existing definition for cwd().
238              
239             unless ($METHOD_MAP{$^O}{cwd} or defined &cwd) {
240             # The pwd command is not available in some chroot(2)'ed environments
241             my $sep = $Config::Config{path_sep} || ':';
242             my $os = $^O; # Protect $^O from tainting
243              
244              
245             # Try again to find a pwd, this time searching the whole PATH.
246             if (defined $ENV{PATH} and $os ne 'MSWin32') { # no pwd on Windows
247             my @candidates = split($sep, $ENV{PATH});
248             while (!$found_pwd_cmd and @candidates) {
249             my $candidate = shift @candidates;
250             $found_pwd_cmd = 1 if -x "$candidate/pwd";
251             }
252             }
253              
254             # MacOS has some special magic to make `pwd` work.
255             if( $os eq 'MacOS' || $found_pwd_cmd )
256             {
257             *cwd = \&_backtick_pwd;
258             }
259             else {
260             *cwd = \&getcwd;
261             }
262             }
263              
264             if ($^O eq 'cygwin') {
265             # We need to make sure cwd() is called with no args, because it's
266             # got an arg-less prototype and will die if args are present.
267             local $^W = 0;
268             my $orig_cwd = \&cwd;
269             *cwd = sub { &$orig_cwd() }
270             }
271              
272              
273             # set a reasonable (and very safe) default for fastgetcwd, in case it
274             # isn't redefined later (20001212 rspier)
275             *fastgetcwd = \&cwd;
276              
277             # A non-XS version of getcwd() - also used to bootstrap the perl build
278             # process, when miniperl is running and no XS loading happens.
279             sub _perl_getcwd
280             {
281 0     0     abs_path('.');
282             }
283              
284             # By John Bazik
285             #
286             # Usage: $cwd = &fastcwd;
287             #
288             # This is a faster version of getcwd. It's also more dangerous because
289             # you might chdir out of a directory that you can't chdir back into.
290            
291             sub fastcwd_ {
292 0     0 0   my($odev, $oino, $cdev, $cino, $tdev, $tino);
293 0           my(@path, $path);
294 0           local(*DIR);
295              
296 0           my($orig_cdev, $orig_cino) = stat('.');
297 0           ($cdev, $cino) = ($orig_cdev, $orig_cino);
298 0           for (;;) {
299 0           my $direntry;
300 0           ($odev, $oino) = ($cdev, $cino);
301 0 0         CORE::chdir('..') || return undef;
302 0           ($cdev, $cino) = stat('.');
303 0 0 0       last if $odev == $cdev && $oino == $cino;
304 0 0         opendir(DIR, '.') || return undef;
305 0           for (;;) {
306 0           $direntry = readdir(DIR);
307 0 0         last unless defined $direntry;
308 0 0         next if $direntry eq '.';
309 0 0         next if $direntry eq '..';
310              
311 0           ($tdev, $tino) = lstat($direntry);
312 0 0 0       last unless $tdev != $odev || $tino != $oino;
313             }
314 0           closedir(DIR);
315 0 0         return undef unless defined $direntry; # should never happen
316 0           unshift(@path, $direntry);
317             }
318 0           $path = '/' . join('/', @path);
319 0 0         if ($^O eq 'apollo') { $path = "/".$path; }
  0            
320             # At this point $path may be tainted (if tainting) and chdir would fail.
321             # Untaint it then check that we landed where we started.
322 0 0 0       $path =~ /^(.*)\z/s # untaint
323             && CORE::chdir($1) or return undef;
324 0           ($cdev, $cino) = stat('.');
325 0 0 0       die "Unstable directory path, current directory changed unexpectedly"
326             if $cdev != $orig_cdev || $cino != $orig_cino;
327 0           $path;
328             }
329             if (not defined &fastcwd) { *fastcwd = \&fastcwd_ }
330              
331              
332             # Keeps track of current working directory in PWD environment var
333             # Usage:
334             # use Cwd 'chdir';
335             # chdir $newdir;
336              
337             my $chdir_init = 0;
338              
339             sub chdir_init {
340 0 0 0 0 0   if ($ENV{'PWD'} and $^O ne 'os2' and $^O ne 'dos' and $^O ne 'MSWin32') {
      0        
      0        
341 0           my($dd,$di) = stat('.');
342 0           my($pd,$pi) = stat($ENV{'PWD'});
343 0 0 0       if (!defined $dd or !defined $pd or $di != $pi or $dd != $pd) {
      0        
      0        
344 0           $ENV{'PWD'} = cwd();
345             }
346             }
347             else {
348 0           my $wd = cwd();
349 0 0         $wd = Win32::GetFullPathName($wd) if $^O eq 'MSWin32';
350 0           $ENV{'PWD'} = $wd;
351             }
352             # Strip an automounter prefix (where /tmp_mnt/foo/bar == /foo/bar)
353 0 0 0       if ($^O ne 'MSWin32' and $ENV{'PWD'} =~ m|(/[^/]+(/[^/]+/[^/]+))(.*)|s) {
354 0           my($pd,$pi) = stat($2);
355 0           my($dd,$di) = stat($1);
356 0 0 0       if (defined $pd and defined $dd and $di == $pi and $dd == $pd) {
      0        
      0        
357 0           $ENV{'PWD'}="$2$3";
358             }
359             }
360 0           $chdir_init = 1;
361             }
362              
363             sub chdir {
364 0 0   0 0   my $newdir = @_ ? shift : ''; # allow for no arg (chdir to HOME dir)
365 0 0         if ($^O eq "cygwin") {
    0          
366 0           $newdir =~ s|\A///+|//|;
367 0           $newdir =~ s|(?<=[^/])//+|/|g;
368             }
369             elsif ($^O ne 'MSWin32') {
370 0           $newdir =~ s|///*|/|g;
371             }
372 0 0         chdir_init() unless $chdir_init;
373 0           my $newpwd;
374 0 0         if ($^O eq 'MSWin32') {
375             # get the full path name *before* the chdir()
376 0           $newpwd = Win32::GetFullPathName($newdir);
377             }
378              
379 0 0         return 0 unless CORE::chdir $newdir;
380              
381 0 0         if ($^O eq 'VMS') {
    0          
    0          
382 0           return $ENV{'PWD'} = $ENV{'DEFAULT'}
383             }
384             elsif ($^O eq 'MacOS') {
385 0           return $ENV{'PWD'} = cwd();
386             }
387             elsif ($^O eq 'MSWin32') {
388 0           $ENV{'PWD'} = $newpwd;
389 0           return 1;
390             }
391              
392 0 0         if (ref $newdir eq 'GLOB') { # in case a file/dir handle is passed in
    0          
393 0           $ENV{'PWD'} = cwd();
394             } elsif ($newdir =~ m#^/#s) {
395 0           $ENV{'PWD'} = $newdir;
396             } else {
397 0           my @curdir = split(m#/#,$ENV{'PWD'});
398 0 0         @curdir = ('') unless @curdir;
399 0           my $component;
400 0           foreach $component (split(m#/#, $newdir)) {
401 0 0         next if $component eq '.';
402 0 0         pop(@curdir),next if $component eq '..';
403 0           push(@curdir,$component);
404             }
405 0   0       $ENV{'PWD'} = join('/',@curdir) || '/';
406             }
407 0           1;
408             }
409              
410              
411             sub _perl_abs_path
412             {
413 0 0   0     my $start = @_ ? shift : '.';
414 0           my($dotdots, $cwd, @pst, @cst, $dir, @tst);
415              
416 0 0         unless (@cst = stat( $start ))
417             {
418 0           _carp("stat($start): $!");
419 0           return '';
420             }
421              
422 0 0         unless (-d _) {
423             # Make sure we can be invoked on plain files, not just directories.
424             # NOTE that this routine assumes that '/' is the only directory separator.
425            
426 0 0         my ($dir, $file) = $start =~ m{^(.*)/(.+)$}
427             or return cwd() . '/' . $start;
428            
429             # Can't use "-l _" here, because the previous stat was a stat(), not an lstat().
430 0 0         if (-l $start) {
431 0           my $link_target = readlink($start);
432 0 0         die "Can't resolve link $start: $!" unless defined $link_target;
433            
434 0           require File::Spec;
435 0 0         $link_target = $dir . '/' . $link_target
436             unless File::Spec->file_name_is_absolute($link_target);
437            
438 0           return abs_path($link_target);
439             }
440            
441 0 0         return $dir ? abs_path($dir) . "/$file" : "/$file";
442             }
443              
444 0           $cwd = '';
445 0           $dotdots = $start;
446             do
447 0           {
448 0           $dotdots .= '/..';
449 0           @pst = @cst;
450 0           local *PARENT;
451 0 0         unless (opendir(PARENT, $dotdots))
452             {
453             # probably a permissions issue. Try the native command.
454 0           require File::Spec;
455 0           return File::Spec->rel2abs( $start, _backtick_pwd() );
456             }
457 0 0         unless (@cst = stat($dotdots))
458             {
459 0           _carp("stat($dotdots): $!");
460 0           closedir(PARENT);
461 0           return '';
462             }
463 0 0 0       if ($pst[0] == $cst[0] && $pst[1] == $cst[1])
464             {
465 0           $dir = undef;
466             }
467             else
468             {
469             do
470 0   0       {
      0        
      0        
471 0 0         unless (defined ($dir = readdir(PARENT)))
472             {
473 0           _carp("readdir($dotdots): $!");
474 0           closedir(PARENT);
475 0           return '';
476             }
477 0 0         $tst[0] = $pst[0]+1 unless (@tst = lstat("$dotdots/$dir"))
478             }
479             while ($dir eq '.' || $dir eq '..' || $tst[0] != $pst[0] ||
480             $tst[1] != $pst[1]);
481             }
482 0 0         $cwd = (defined $dir ? "$dir" : "" ) . "/$cwd" ;
483 0           closedir(PARENT);
484             } while (defined $dir);
485 0 0         chop($cwd) unless $cwd eq '/'; # drop the trailing /
486 0           $cwd;
487             }
488              
489              
490             my $Curdir;
491             sub fast_abs_path {
492 0   0 0 1   local $ENV{PWD} = $ENV{PWD} || ''; # Guard against clobberage
493 0           my $cwd = getcwd();
494 0           require File::Spec;
495 0 0 0       my $path = @_ ? shift : ($Curdir ||= File::Spec->curdir);
496              
497             # Detaint else we'll explode in taint mode. This is safe because
498             # we're not doing anything dangerous with it.
499 0           ($path) = $path =~ /(.*)/s;
500 0           ($cwd) = $cwd =~ /(.*)/s;
501              
502 0 0         unless (-e $path) {
503 0           _croak("$path: No such file or directory");
504             }
505              
506 0 0         unless (-d _) {
507             # Make sure we can be invoked on plain files, not just directories.
508            
509 0           my ($vol, $dir, $file) = File::Spec->splitpath($path);
510 0 0         return File::Spec->catfile($cwd, $path) unless length $dir;
511              
512 0 0         if (-l $path) {
513 0           my $link_target = readlink($path);
514 0 0         die "Can't resolve link $path: $!" unless defined $link_target;
515            
516 0 0         $link_target = File::Spec->catpath($vol, $dir, $link_target)
517             unless File::Spec->file_name_is_absolute($link_target);
518            
519 0           return fast_abs_path($link_target);
520             }
521            
522 0 0         return $dir eq File::Spec->rootdir
523             ? File::Spec->catpath($vol, $dir, $file)
524             : fast_abs_path(File::Spec->catpath($vol, $dir, '')) . '/' . $file;
525             }
526              
527 0 0         if (!CORE::chdir($path)) {
528 0           _croak("Cannot chdir to $path: $!");
529             }
530 0           my $realpath = getcwd();
531 0 0 0       if (! ((-d $cwd) && (CORE::chdir($cwd)))) {
532 0           _croak("Cannot chdir back to $cwd: $!");
533             }
534 0           $realpath;
535             }
536              
537             # added function alias to follow principle of least surprise
538             # based on previous aliasing. --tchrist 27-Jan-00
539             *fast_realpath = \&fast_abs_path;
540              
541              
542             # --- PORTING SECTION ---
543              
544             # VMS: $ENV{'DEFAULT'} points to default directory at all times
545             # 06-Mar-1996 Charles Bailey bailey@newman.upenn.edu
546             # Note: Use of Cwd::chdir() causes the logical name PWD to be defined
547             # in the process logical name table as the default device and directory
548             # seen by Perl. This may not be the same as the default device
549             # and directory seen by DCL after Perl exits, since the effects
550             # the CRTL chdir() function persist only until Perl exits.
551              
552             sub _vms_cwd {
553 0     0     return $ENV{'DEFAULT'};
554             }
555              
556             sub _vms_abs_path {
557 0 0   0     return $ENV{'DEFAULT'} unless @_;
558 0           my $path = shift;
559              
560 0           my $efs = _vms_efs;
561 0           my $unix_rpt = _vms_unix_rpt;
562              
563 0 0         if (defined &VMS::Filespec::vmsrealpath) {
564 0           my $path_unix = 0;
565 0           my $path_vms = 0;
566              
567 0 0         $path_unix = 1 if ($path =~ m#(?<=\^)/#);
568 0 0         $path_unix = 1 if ($path =~ /^\.\.?$/);
569 0 0         $path_vms = 1 if ($path =~ m#[\[<\]]#);
570 0 0         $path_vms = 1 if ($path =~ /^--?$/);
571              
572 0           my $unix_mode = $path_unix;
573 0 0         if ($efs) {
574             # In case of a tie, the Unix report mode decides.
575 0 0         if ($path_vms == $path_unix) {
576 0           $unix_mode = $unix_rpt;
577             } else {
578 0 0         $unix_mode = 0 if $path_vms;
579             }
580             }
581              
582 0 0         if ($unix_mode) {
583             # Unix format
584 0           return VMS::Filespec::unixrealpath($path);
585             }
586              
587             # VMS format
588              
589 0           my $new_path = VMS::Filespec::vmsrealpath($path);
590              
591             # Perl expects directories to be in directory format
592 0 0         $new_path = VMS::Filespec::pathify($new_path) if -d $path;
593 0           return $new_path;
594             }
595              
596             # Fallback to older algorithm if correct ones are not
597             # available.
598              
599 0 0         if (-l $path) {
600 0           my $link_target = readlink($path);
601 0 0         die "Can't resolve link $path: $!" unless defined $link_target;
602              
603 0           return _vms_abs_path($link_target);
604             }
605              
606             # may need to turn foo.dir into [.foo]
607 0           my $pathified = VMS::Filespec::pathify($path);
608 0 0         $path = $pathified if defined $pathified;
609            
610 0           return VMS::Filespec::rmsexpand($path);
611             }
612              
613             sub _os2_cwd {
614 0     0     my $pwd = `cmd /c cd`;
615 0           chomp $pwd;
616 0           $pwd =~ s:\\:/:g ;
617 0           $ENV{'PWD'} = $pwd;
618 0           return $pwd;
619             }
620              
621             sub _win32_cwd_simple {
622 0     0     my $pwd = `cd`;
623 0           chomp $pwd;
624 0           $pwd =~ s:\\:/:g ;
625 0           $ENV{'PWD'} = $pwd;
626 0           return $pwd;
627             }
628              
629             sub _win32_cwd {
630 0     0     my $pwd;
631 0           $pwd = Win32::GetCwd();
632 0           $pwd =~ s:\\:/:g ;
633 0           $ENV{'PWD'} = $pwd;
634 0           return $pwd;
635             }
636              
637             *_NT_cwd = defined &Win32::GetCwd ? \&_win32_cwd : \&_win32_cwd_simple;
638              
639             sub _dos_cwd {
640 0     0     my $pwd;
641 0 0         if (!defined &Dos::GetCwd) {
642 0           chomp($pwd = `command /c cd`);
643 0           $pwd =~ s:\\:/:g ;
644             } else {
645 0           $pwd = Dos::GetCwd();
646             }
647 0           $ENV{'PWD'} = $pwd;
648 0           return $pwd;
649             }
650              
651             sub _qnx_cwd {
652 0     0     local $ENV{PATH} = '';
653 0           local $ENV{CDPATH} = '';
654 0           local $ENV{ENV} = '';
655 0           my $pwd = `/usr/bin/fullpath -t`;
656 0           chomp $pwd;
657 0           $ENV{'PWD'} = $pwd;
658 0           return $pwd;
659             }
660              
661             sub _qnx_abs_path {
662 0     0     local $ENV{PATH} = '';
663 0           local $ENV{CDPATH} = '';
664 0           local $ENV{ENV} = '';
665 0 0         my $path = @_ ? shift : '.';
666 0           local *REALPATH;
667              
668 0 0 0       defined( open(REALPATH, '-|') || exec '/usr/bin/fullpath', '-t', $path ) or
669             die "Can't open /usr/bin/fullpath: $!";
670 0           my $realpath = ;
671 0           close REALPATH;
672 0           chomp $realpath;
673 0           return $realpath;
674             }
675              
676             sub _epoc_cwd {
677 0     0     return $ENV{'PWD'} = EPOC::getcwd();
678             }
679              
680              
681             # Now that all the base-level functions are set up, alias the
682             # user-level functions to the right places
683              
684             if (exists $METHOD_MAP{$^O}) {
685             my $map = $METHOD_MAP{$^O};
686             foreach my $name (keys %$map) {
687             local $^W = 0; # assignments trigger 'subroutine redefined' warning
688             no strict 'refs';
689             *{$name} = \&{$map->{$name}};
690             }
691             }
692              
693             # In case the XS version doesn't load.
694             *abs_path = \&_perl_abs_path unless defined &abs_path;
695             *getcwd = \&_perl_getcwd unless defined &getcwd;
696              
697             # added function alias for those of us more
698             # used to the libc function. --tchrist 27-Jan-00
699             *realpath = \&abs_path;
700              
701             1;
702             __END__