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