disallow eval { goto &foo }
[p5sagit/p5-mst-13.2.git] / lib / Cwd.pm
CommitLineData
a0d0e21e 1package Cwd;
a0d0e21e 2
f06db76b 3=head1 NAME
4
902bacac 5Cwd - get pathname of current working directory
f06db76b 6
7=head1 SYNOPSIS
8
4633a7c4 9 use Cwd;
04929354 10 my $dir = getcwd;
4633a7c4 11
04929354 12 use Cwd 'abs_path';
13 my $abs_path = abs_path($file);
f06db76b 14
04929354 15=head1 DESCRIPTION
902bacac 16
04929354 17This module provides functions for determining the pathname of the
18current working directory. It is recommended that getcwd (or another
19*cwd() function) be used in I<all> code to ensure portability.
f06db76b 20
04929354 21By default, it exports the functions cwd(), getcwd(), fastcwd(), and
09122b95 22fastgetcwd() (and, on Win32, getdcwd()) into the caller's namespace.
f06db76b 23
20408e3c 24
04929354 25=head2 getcwd and friends
20408e3c 26
04929354 27Each of these functions are called without arguments and return the
28absolute path of the current working directory.
f06db76b 29
04929354 30=over 4
31
32=item getcwd
33
34 my $cwd = getcwd();
35
36Returns the current working directory.
37
38Re-implements the getcwd(3) (or getwd(3)) functions in Perl.
39
40=item cwd
41
42 my $cwd = cwd();
43
44The cwd() is the most natural form for the current architecture. For
45most systems it is identical to `pwd` (but without the trailing line
46terminator).
47
04929354 48=item fastcwd
49
50 my $cwd = fastcwd();
51
52A more dangerous version of getcwd(), but potentially faster.
53
54It might conceivably chdir() you out of a directory that it can't
55chdir() you back into. If fastcwd encounters a problem it will return
56undef but will probably leave you in a different directory. For a
57measure of extra security, if everything appears to have worked, the
58fastcwd() function will check that it leaves you in the same directory
59that it started in. If it has changed it will C<die> with the message
60"Unstable directory path, current directory changed
61unexpectedly". That should never happen.
62
63=item fastgetcwd
64
65 my $cwd = fastgetcwd();
f06db76b 66
902bacac 67The fastgetcwd() function is provided as a synonym for cwd().
fb73857a 68
09122b95 69=item getdcwd
70
71 my $cwd = getdcwd();
72 my $cwd = getdcwd('C:');
73
74The getdcwd() function is also provided on Win32 to get the current working
75directory on the specified drive, since Windows maintains a separate current
76working directory for each drive. If no drive is specified then the current
77drive is assumed.
78
79This function simply calls the Microsoft C library _getdcwd() function.
80
04929354 81=back
82
902bacac 83
04929354 84=head2 abs_path and friends
85
86These functions are exported only on request. They each take a single
3ee63918 87argument and return the absolute pathname for it. If no argument is
88given they'll use the current working directory.
04929354 89
90=over 4
91
92=item abs_path
93
94 my $abs_path = abs_path($file);
95
96Uses the same algorithm as getcwd(). Symbolic links and relative-path
97components ("." and "..") are resolved to return the canonical
98pathname, just like realpath(3).
99
100=item realpath
101
102 my $abs_path = realpath($file);
103
104A synonym for abs_path().
105
106=item fast_abs_path
107
510179aa 108 my $abs_path = fast_abs_path($file);
04929354 109
110A more dangerous, but potentially faster version of abs_path.
111
112=back
113
114=head2 $ENV{PWD}
115
116If you ask to override your chdir() built-in function,
117
118 use Cwd qw(chdir);
119
120then your PWD environment variable will be kept up to date. Note that
121it will only be kept up to date if all packages which use chdir import
122it from Cwd.
4633a7c4 123
4633a7c4 124
4d6b4052 125=head1 NOTES
126
127=over 4
128
129=item *
130
04929354 131Since the path seperators are different on some operating systems ('/'
132on Unix, ':' on MacPerl, etc...) we recommend you use the File::Spec
133modules wherever portability is a concern.
134
04929354 135=item *
4d6b4052 136
137Actually, on Mac OS, the C<getcwd()>, C<fastgetcwd()> and C<fastcwd()>
138functions are all aliases for the C<cwd()> function, which, on Mac OS,
139calls `pwd`. Likewise, the C<abs_path()> function is an alias for
140C<fast_abs_path()>.
141
142=back
143
02cc4877 144=head1 AUTHOR
145
146Originally by the perl5-porters.
147
78321866 148Maintained by Ken Williams <KWILLIAMS@cpan.org>
02cc4877 149
99f36a73 150=head1 COPYRIGHT
151
152Copyright (c) 2004 by the Perl 5 Porters. All rights reserved.
153
154This program is free software; you can redistribute it and/or modify
155it under the same terms as Perl itself.
156
157Portions of the C code in this library are copyright (c) 1994 by the
158Regents of the University of California. All rights reserved. The
159license on this code is compatible with the licensing of the rest of
160the distribution - please see the source code in F<Cwd.xs> for the
161details.
162
04929354 163=head1 SEE ALSO
164
165L<File::chdir>
166
f06db76b 167=cut
168
b060a406 169use strict;
a9939470 170use Exporter;
99f36a73 171use vars qw(@ISA @EXPORT @EXPORT_OK $VERSION);
172
60598624 173$VERSION = '3.07';
96e4d5b1 174
a9939470 175@ISA = qw/ Exporter /;
176@EXPORT = qw(cwd getcwd fastcwd fastgetcwd);
09122b95 177push @EXPORT, qw(getdcwd) if $^O eq 'MSWin32';
a9939470 178@EXPORT_OK = qw(chdir abs_path fast_abs_path realpath fast_realpath);
a0d0e21e 179
f5f423e4 180# sys_cwd may keep the builtin command
181
182# All the functionality of this module may provided by builtins,
183# there is no sense to process the rest of the file.
184# The best choice may be to have this in BEGIN, but how to return from BEGIN?
185
a9939470 186if ($^O eq 'os2') {
f5f423e4 187 local $^W = 0;
a9939470 188
189 *cwd = defined &sys_cwd ? \&sys_cwd : \&_os2_cwd;
190 *getcwd = \&cwd;
191 *fastgetcwd = \&cwd;
192 *fastcwd = \&cwd;
193
194 *fast_abs_path = \&sys_abspath if defined &sys_abspath;
195 *abs_path = \&fast_abs_path;
196 *realpath = \&fast_abs_path;
197 *fast_realpath = \&fast_abs_path;
198
f5f423e4 199 return 1;
200}
201
b04f6d36 202# If loading the XS stuff doesn't work, we can fall back to pure perl
f22d8e4b 203eval {
b04f6d36 204 if ( $] >= 5.006 ) {
205 require XSLoader;
206 XSLoader::load( __PACKAGE__, $VERSION );
207 } else {
208 require DynaLoader;
209 push @ISA, 'DynaLoader';
210 __PACKAGE__->bootstrap( $VERSION );
211 }
f22d8e4b 212};
4633a7c4 213
99f36a73 214# Must be after the DynaLoader stuff:
215$VERSION = eval $VERSION;
216
09122b95 217# Big nasty table of function aliases
218my %METHOD_MAP =
219 (
220 VMS =>
221 {
222 cwd => '_vms_cwd',
223 getcwd => '_vms_cwd',
224 fastcwd => '_vms_cwd',
225 fastgetcwd => '_vms_cwd',
226 abs_path => '_vms_abs_path',
227 fast_abs_path => '_vms_abs_path',
228 },
229
230 MSWin32 =>
231 {
232 # We assume that &_NT_cwd is defined as an XSUB or in the core.
233 cwd => '_NT_cwd',
234 getcwd => '_NT_cwd',
235 fastcwd => '_NT_cwd',
236 fastgetcwd => '_NT_cwd',
237 abs_path => 'fast_abs_path',
238 realpath => 'fast_abs_path',
239 },
240
241 dos =>
242 {
243 cwd => '_dos_cwd',
244 getcwd => '_dos_cwd',
245 fastgetcwd => '_dos_cwd',
246 fastcwd => '_dos_cwd',
247 abs_path => 'fast_abs_path',
248 },
249
250 qnx =>
251 {
252 cwd => '_qnx_cwd',
253 getcwd => '_qnx_cwd',
254 fastgetcwd => '_qnx_cwd',
255 fastcwd => '_qnx_cwd',
256 abs_path => '_qnx_abs_path',
257 fast_abs_path => '_qnx_abs_path',
258 },
259
260 cygwin =>
261 {
262 getcwd => 'cwd',
263 fastgetcwd => 'cwd',
264 fastcwd => 'cwd',
265 abs_path => 'fast_abs_path',
266 realpath => 'fast_abs_path',
267 },
268
269 epoc =>
270 {
271 cwd => '_epoc_cwd',
272 getcwd => '_epoc_cwd',
273 fastgetcwd => '_epoc_cwd',
274 fastcwd => '_epoc_cwd',
275 abs_path => 'fast_abs_path',
276 },
277
278 MacOS =>
279 {
280 getcwd => 'cwd',
281 fastgetcwd => 'cwd',
282 fastcwd => 'cwd',
283 abs_path => 'fast_abs_path',
284 },
285 );
286
287$METHOD_MAP{NT} = $METHOD_MAP{MSWin32};
288$METHOD_MAP{nto} = $METHOD_MAP{qnx};
289
96e4d5b1 290
3547aa9a 291# Find the pwd command in the expected locations. We assume these
292# are safe. This prevents _backtick_pwd() consulting $ENV{PATH}
293# so everything works under taint mode.
294my $pwd_cmd;
889f7a4f 295foreach my $try ('/bin/pwd',
296 '/usr/bin/pwd',
297 '/QOpenSys/bin/pwd', # OS/400 PASE.
298 ) {
299
3547aa9a 300 if( -x $try ) {
301 $pwd_cmd = $try;
302 last;
303 }
304}
522b859a 305unless ($pwd_cmd) {
889f7a4f 306 # Isn't this wrong? _backtick_pwd() will fail if somenone has
307 # pwd in their path but it is not /bin/pwd or /usr/bin/pwd?
308 # See [perl #16774]. --jhi
309 $pwd_cmd = 'pwd';
522b859a 310}
3547aa9a 311
a9939470 312# Lazy-load Carp
313sub _carp { require Carp; Carp::carp(@_) }
314sub _croak { require Carp; Carp::croak(@_) }
315
3547aa9a 316# The 'natural and safe form' for UNIX (pwd may be setuid root)
8b88ae92 317sub _backtick_pwd {
db281859 318 local @ENV{qw(PATH IFS CDPATH ENV BASH_ENV)};
3547aa9a 319 my $cwd = `$pwd_cmd`;
ac3b20cb 320 # Belt-and-suspenders in case someone said "undef $/".
5cf6da5f 321 local $/ = "\n";
ac3b20cb 322 # `pwd` may fail e.g. if the disk is full
7e03f963 323 chomp($cwd) if defined $cwd;
4633a7c4 324 $cwd;
8b88ae92 325}
4633a7c4 326
327# Since some ports may predefine cwd internally (e.g., NT)
328# we take care not to override an existing definition for cwd().
329
09122b95 330unless ($METHOD_MAP{$^O}{cwd} or defined &cwd) {
ea54c8bd 331 # The pwd command is not available in some chroot(2)'ed environments
09122b95 332 my $sep = $Config::Config{path_sep} || ':';
60598624 333 my $os = $^O; # Protect $^O from tainting
334 if( $os eq 'MacOS' || (defined $ENV{PATH} &&
335 $os ne 'MSWin32' && # no pwd on Windows
09122b95 336 grep { -x "$_/pwd" } split($sep, $ENV{PATH})) )
73b801a6 337 {
ea54c8bd 338 *cwd = \&_backtick_pwd;
339 }
340 else {
341 *cwd = \&getcwd;
342 }
343}
a0d0e21e 344
1f4f94f5 345# set a reasonable (and very safe) default for fastgetcwd, in case it
346# isn't redefined later (20001212 rspier)
347*fastgetcwd = \&cwd;
748a9306 348
a0d0e21e 349# By Brandon S. Allbery
350#
351# Usage: $cwd = getcwd();
352
353sub getcwd
354{
07569ed3 355 abs_path('.');
a0d0e21e 356}
357
a0c9c202 358
359# By John Bazik
360#
361# Usage: $cwd = &fastcwd;
362#
363# This is a faster version of getcwd. It's also more dangerous because
364# you might chdir out of a directory that you can't chdir back into.
365
99f36a73 366sub fastcwd_ {
a0c9c202 367 my($odev, $oino, $cdev, $cino, $tdev, $tino);
368 my(@path, $path);
369 local(*DIR);
370
371 my($orig_cdev, $orig_cino) = stat('.');
372 ($cdev, $cino) = ($orig_cdev, $orig_cino);
373 for (;;) {
374 my $direntry;
375 ($odev, $oino) = ($cdev, $cino);
376 CORE::chdir('..') || return undef;
377 ($cdev, $cino) = stat('.');
378 last if $odev == $cdev && $oino == $cino;
379 opendir(DIR, '.') || return undef;
380 for (;;) {
381 $direntry = readdir(DIR);
382 last unless defined $direntry;
383 next if $direntry eq '.';
384 next if $direntry eq '..';
385
386 ($tdev, $tino) = lstat($direntry);
387 last unless $tdev != $odev || $tino != $oino;
388 }
389 closedir(DIR);
390 return undef unless defined $direntry; # should never happen
391 unshift(@path, $direntry);
392 }
393 $path = '/' . join('/', @path);
394 if ($^O eq 'apollo') { $path = "/".$path; }
395 # At this point $path may be tainted (if tainting) and chdir would fail.
248785eb 396 # Untaint it then check that we landed where we started.
397 $path =~ /^(.*)\z/s # untaint
398 && CORE::chdir($1) or return undef;
a0c9c202 399 ($cdev, $cino) = stat('.');
400 die "Unstable directory path, current directory changed unexpectedly"
401 if $cdev != $orig_cdev || $cino != $orig_cino;
402 $path;
403}
99f36a73 404if (not defined &fastcwd) { *fastcwd = \&fastcwd_ }
a0c9c202 405
406
4633a7c4 407# Keeps track of current working directory in PWD environment var
a0d0e21e 408# Usage:
409# use Cwd 'chdir';
410# chdir $newdir;
411
4633a7c4 412my $chdir_init = 0;
a0d0e21e 413
4633a7c4 414sub chdir_init {
3b8e3443 415 if ($ENV{'PWD'} and $^O ne 'os2' and $^O ne 'dos' and $^O ne 'MSWin32') {
a0d0e21e 416 my($dd,$di) = stat('.');
417 my($pd,$pi) = stat($ENV{'PWD'});
418 if (!defined $dd or !defined $pd or $di != $pi or $dd != $pd) {
4633a7c4 419 $ENV{'PWD'} = cwd();
a0d0e21e 420 }
421 }
422 else {
3b8e3443 423 my $wd = cwd();
424 $wd = Win32::GetFullPathName($wd) if $^O eq 'MSWin32';
425 $ENV{'PWD'} = $wd;
a0d0e21e 426 }
4633a7c4 427 # Strip an automounter prefix (where /tmp_mnt/foo/bar == /foo/bar)
3b8e3443 428 if ($^O ne 'MSWin32' and $ENV{'PWD'} =~ m|(/[^/]+(/[^/]+/[^/]+))(.*)|s) {
a0d0e21e 429 my($pd,$pi) = stat($2);
430 my($dd,$di) = stat($1);
431 if (defined $pd and defined $dd and $di == $pi and $dd == $pd) {
432 $ENV{'PWD'}="$2$3";
433 }
434 }
435 $chdir_init = 1;
436}
437
438sub chdir {
22978713 439 my $newdir = @_ ? shift : ''; # allow for no arg (chdir to HOME dir)
3b8e3443 440 $newdir =~ s|///*|/|g unless $^O eq 'MSWin32';
a0d0e21e 441 chdir_init() unless $chdir_init;
4ffa1610 442 my $newpwd;
443 if ($^O eq 'MSWin32') {
444 # get the full path name *before* the chdir()
445 $newpwd = Win32::GetFullPathName($newdir);
446 }
447
4633a7c4 448 return 0 unless CORE::chdir $newdir;
4ffa1610 449
3b8e3443 450 if ($^O eq 'VMS') {
451 return $ENV{'PWD'} = $ENV{'DEFAULT'}
452 }
4aecb5b5 453 elsif ($^O eq 'MacOS') {
454 return $ENV{'PWD'} = cwd();
455 }
3b8e3443 456 elsif ($^O eq 'MSWin32') {
4ffa1610 457 $ENV{'PWD'} = $newpwd;
3b8e3443 458 return 1;
459 }
748a9306 460
392d8ab8 461 if ($newdir =~ m#^/#s) {
a0d0e21e 462 $ENV{'PWD'} = $newdir;
4633a7c4 463 } else {
464 my @curdir = split(m#/#,$ENV{'PWD'});
465 @curdir = ('') unless @curdir;
466 my $component;
a0d0e21e 467 foreach $component (split(m#/#, $newdir)) {
468 next if $component eq '.';
469 pop(@curdir),next if $component eq '..';
470 push(@curdir,$component);
471 }
472 $ENV{'PWD'} = join('/',@curdir) || '/';
473 }
4633a7c4 474 1;
a0d0e21e 475}
476
a0c9c202 477
99f36a73 478sub _perl_abs_path
a0c9c202 479{
480 my $start = @_ ? shift : '.';
481 my($dotdots, $cwd, @pst, @cst, $dir, @tst);
482
483 unless (@cst = stat( $start ))
484 {
a9939470 485 _carp("stat($start): $!");
a0c9c202 486 return '';
487 }
09122b95 488
489 unless (-d _) {
490 # Make sure we can be invoked on plain files, not just directories.
491 # NOTE that this routine assumes that '/' is the only directory separator.
492
493 my ($dir, $file) = $start =~ m{^(.*)/(.+)$}
494 or return cwd() . '/' . $start;
495
275e8705 496 # Can't use "-l _" here, because the previous stat was a stat(), not an lstat().
497 if (-l $start) {
09122b95 498 my $link_target = readlink($start);
499 die "Can't resolve link $start: $!" unless defined $link_target;
500
501 require File::Spec;
502 $link_target = $dir . '/' . $link_target
503 unless File::Spec->file_name_is_absolute($link_target);
504
505 return abs_path($link_target);
506 }
507
99f36a73 508 return $dir ? abs_path($dir) . "/$file" : "/$file";
09122b95 509 }
510
a0c9c202 511 $cwd = '';
512 $dotdots = $start;
513 do
514 {
515 $dotdots .= '/..';
516 @pst = @cst;
a25ef67d 517 local *PARENT;
a0c9c202 518 unless (opendir(PARENT, $dotdots))
519 {
a9939470 520 _carp("opendir($dotdots): $!");
a0c9c202 521 return '';
522 }
523 unless (@cst = stat($dotdots))
524 {
a9939470 525 _carp("stat($dotdots): $!");
a0c9c202 526 closedir(PARENT);
527 return '';
528 }
529 if ($pst[0] == $cst[0] && $pst[1] == $cst[1])
530 {
531 $dir = undef;
532 }
533 else
534 {
535 do
536 {
537 unless (defined ($dir = readdir(PARENT)))
538 {
a9939470 539 _carp("readdir($dotdots): $!");
a0c9c202 540 closedir(PARENT);
541 return '';
542 }
543 $tst[0] = $pst[0]+1 unless (@tst = lstat("$dotdots/$dir"))
544 }
545 while ($dir eq '.' || $dir eq '..' || $tst[0] != $pst[0] ||
546 $tst[1] != $pst[1]);
547 }
548 $cwd = (defined $dir ? "$dir" : "" ) . "/$cwd" ;
549 closedir(PARENT);
550 } while (defined $dir);
551 chop($cwd) unless $cwd eq '/'; # drop the trailing /
552 $cwd;
553}
554
555
3ee63918 556my $Curdir;
96e4d5b1 557sub fast_abs_path {
99f36a73 558 local $ENV{PWD} = $ENV{PWD} || ''; # Guard against clobberage
96e4d5b1 559 my $cwd = getcwd();
4d6b4052 560 require File::Spec;
3ee63918 561 my $path = @_ ? shift : ($Curdir ||= File::Spec->curdir);
562
563 # Detaint else we'll explode in taint mode. This is safe because
564 # we're not doing anything dangerous with it.
565 ($path) = $path =~ /(.*)/;
566 ($cwd) = $cwd =~ /(.*)/;
567
09122b95 568 unless (-e $path) {
569 _croak("$path: No such file or directory");
570 }
571
572 unless (-d _) {
573 # Make sure we can be invoked on plain files, not just directories.
574
575 my ($vol, $dir, $file) = File::Spec->splitpath($path);
576 return File::Spec->catfile($cwd, $path) unless length $dir;
577
578 if (-l $path) {
579 my $link_target = readlink($path);
580 die "Can't resolve link $path: $!" unless defined $link_target;
581
582 $link_target = File::Spec->catpath($vol, $dir, $link_target)
583 unless File::Spec->file_name_is_absolute($link_target);
584
585 return fast_abs_path($link_target);
586 }
587
8e6a5f51 588 my $tdir = $dir;
589 $tdir =~ s!\\!/!g if $^O eq 'MSWin32';
590 return $tdir eq File::Spec->rootdir
99f36a73 591 ? File::Spec->catpath($vol, $dir, $file)
592 : fast_abs_path(File::Spec->catpath($vol, $dir, '')) . '/' . $file;
09122b95 593 }
594
e2ba406b 595 if (!CORE::chdir($path)) {
a9939470 596 _croak("Cannot chdir to $path: $!");
e2ba406b 597 }
96e4d5b1 598 my $realpath = getcwd();
e2ba406b 599 if (! ((-d $cwd) && (CORE::chdir($cwd)))) {
a9939470 600 _croak("Cannot chdir back to $cwd: $!");
e2ba406b 601 }
96e4d5b1 602 $realpath;
8b88ae92 603}
604
e4c51978 605# added function alias to follow principle of least surprise
606# based on previous aliasing. --tchrist 27-Jan-00
607*fast_realpath = \&fast_abs_path;
608
4633a7c4 609
610# --- PORTING SECTION ---
611
612# VMS: $ENV{'DEFAULT'} points to default directory at all times
bd3fa61c 613# 06-Mar-1996 Charles Bailey bailey@newman.upenn.edu
c6538b72 614# Note: Use of Cwd::chdir() causes the logical name PWD to be defined
8b88ae92 615# in the process logical name table as the default device and directory
616# seen by Perl. This may not be the same as the default device
4633a7c4 617# and directory seen by DCL after Perl exits, since the effects
618# the CRTL chdir() function persist only until Perl exits.
4633a7c4 619
620sub _vms_cwd {
96e4d5b1 621 return $ENV{'DEFAULT'};
622}
623
624sub _vms_abs_path {
625 return $ENV{'DEFAULT'} unless @_;
9d7d9729 626
627 # may need to turn foo.dir into [.foo]
96e4d5b1 628 my $path = VMS::Filespec::pathify($_[0]);
9d7d9729 629 $path = $_[0] unless defined $path;
630
96e4d5b1 631 return VMS::Filespec::rmsexpand($path);
4633a7c4 632}
68dc0745 633
4633a7c4 634sub _os2_cwd {
635 $ENV{'PWD'} = `cmd /c cd`;
39741d73 636 chomp $ENV{'PWD'};
aa6b7957 637 $ENV{'PWD'} =~ s:\\:/:g ;
4633a7c4 638 return $ENV{'PWD'};
639}
640
96e4d5b1 641sub _win32_cwd {
2d7a9237 642 $ENV{'PWD'} = Win32::GetCwd();
aa6b7957 643 $ENV{'PWD'} =~ s:\\:/:g ;
96e4d5b1 644 return $ENV{'PWD'};
645}
646
647*_NT_cwd = \&_win32_cwd if (!defined &_NT_cwd &&
2d7a9237 648 defined &Win32::GetCwd);
96e4d5b1 649
650*_NT_cwd = \&_os2_cwd unless defined &_NT_cwd;
68dc0745 651
39e571d4 652sub _dos_cwd {
653 if (!defined &Dos::GetCwd) {
654 $ENV{'PWD'} = `command /c cd`;
39741d73 655 chomp $ENV{'PWD'};
aa6b7957 656 $ENV{'PWD'} =~ s:\\:/:g ;
39e571d4 657 } else {
658 $ENV{'PWD'} = Dos::GetCwd();
659 }
55497cff 660 return $ENV{'PWD'};
661}
662
7fbf1995 663sub _qnx_cwd {
35b807ef 664 local $ENV{PATH} = '';
665 local $ENV{CDPATH} = '';
666 local $ENV{ENV} = '';
7fbf1995 667 $ENV{'PWD'} = `/usr/bin/fullpath -t`;
39741d73 668 chomp $ENV{'PWD'};
7fbf1995 669 return $ENV{'PWD'};
670}
671
672sub _qnx_abs_path {
35b807ef 673 local $ENV{PATH} = '';
674 local $ENV{CDPATH} = '';
675 local $ENV{ENV} = '';
fa921dc6 676 my $path = @_ ? shift : '.';
39741d73 677 local *REALPATH;
678
99f36a73 679 defined( open(REALPATH, '-|') || exec '/usr/bin/fullpath', '-t', $path ) or
39741d73 680 die "Can't open /usr/bin/fullpath: $!";
681 my $realpath = <REALPATH>;
682 close REALPATH;
683 chomp $realpath;
7fbf1995 684 return $realpath;
685}
686
ed79a026 687sub _epoc_cwd {
688 $ENV{'PWD'} = EPOC::getcwd();
689 return $ENV{'PWD'};
690}
691
4633a7c4 692
09122b95 693# Now that all the base-level functions are set up, alias the
694# user-level functions to the right places
695
696if (exists $METHOD_MAP{$^O}) {
697 my $map = $METHOD_MAP{$^O};
698 foreach my $name (keys %$map) {
99f36a73 699 local $^W = 0; # assignments trigger 'subroutine redefined' warning
09122b95 700 no strict 'refs';
701 *{$name} = \&{$map->{$name}};
702 }
55497cff 703}
4633a7c4 704
99f36a73 705# In case the XS version doesn't load.
706*abs_path = \&_perl_abs_path unless defined &abs_path;
707
708# added function alias for those of us more
709# used to the libc function. --tchrist 27-Jan-00
710*realpath = \&abs_path;
4633a7c4 711
a0d0e21e 7121;