Filename | C:/tmp64ng/perl/lib/Cwd.pm |
Statements | Executed 165 statements in 0s |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 0s | 0s | BEGIN@170 | Cwd::
1 | 1 | 1 | 0s | 0s | BEGIN@171 | Cwd::
1 | 1 | 1 | 0s | 0s | BEGIN@172 | Cwd::
1 | 1 | 1 | 0s | 0s | BEGIN@209 | Cwd::
1 | 1 | 1 | 0s | 0s | BEGIN@843 | Cwd::
10 | 2 | 1 | 0s | 0s | CORE:chdir (opcode) | Cwd::
10 | 2 | 1 | 0s | 0s | CORE:ftdir (opcode) | Cwd::
3 | 1 | 1 | 0s | 0s | CORE:fteexec (opcode) | Cwd::
5 | 1 | 1 | 0s | 0s | CORE:ftis (opcode) | Cwd::
11 | 3 | 1 | 0s | 0s | CORE:match (opcode) | Cwd::
15 | 1 | 1 | 0s | 0s | CORE:subst (opcode) | Cwd::
0 | 0 | 0 | 0s | 0s | __ANON__[:423] | Cwd::
0 | 0 | 0 | 0s | 0s | _backtick_pwd | Cwd::
0 | 0 | 0 | 0s | 0s | _carp | Cwd::
0 | 0 | 0 | 0s | 0s | _croak | Cwd::
0 | 0 | 0 | 0s | 0s | _dos_cwd | Cwd::
0 | 0 | 0 | 0s | 0s | _epoc_cwd | Cwd::
0 | 0 | 0 | 0s | 0s | _os2_cwd | Cwd::
0 | 0 | 0 | 0s | 0s | _perl_abs_path | Cwd::
0 | 0 | 0 | 0s | 0s | _perl_getcwd | Cwd::
0 | 0 | 0 | 0s | 0s | _qnx_abs_path | Cwd::
0 | 0 | 0 | 0s | 0s | _qnx_cwd | Cwd::
0 | 0 | 0 | 0s | 0s | _vms_abs_path | Cwd::
0 | 0 | 0 | 0s | 0s | _vms_cwd | Cwd::
0 | 0 | 0 | 0s | 0s | _vms_efs | Cwd::
0 | 0 | 0 | 0s | 0s | _vms_unix_rpt | Cwd::
15 | 5 | 4 | 0s | 0s | _win32_cwd | Cwd::
0 | 0 | 0 | 0s | 0s | _win32_cwd_simple | Cwd::
0 | 0 | 0 | 0s | 0s | chdir | Cwd::
0 | 0 | 0 | 0s | 0s | chdir_init | Cwd::
5 | 1 | 1 | 0s | 0s | fast_abs_path | Cwd::
0 | 0 | 0 | 0s | 0s | fastcwd_ | Cwd::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Cwd; | ||||
2 | |||||
3 | =head1 NAME | ||||
4 | |||||
5 | Cwd - get pathname of current working directory | ||||
6 | |||||
7 | =head1 SYNOPSIS | ||||
8 | |||||
9 | use Cwd; | ||||
10 | my $dir = getcwd; | ||||
11 | |||||
12 | use Cwd 'abs_path'; | ||||
13 | my $abs_path = abs_path($file); | ||||
14 | |||||
15 | =head1 DESCRIPTION | ||||
16 | |||||
17 | This module provides functions for determining the pathname of the | ||||
18 | current working directory. It is recommended that getcwd (or another | ||||
19 | *cwd() function) be used in I<all> code to ensure portability. | ||||
20 | |||||
21 | By default, it exports the functions cwd(), getcwd(), fastcwd(), and | ||||
22 | fastgetcwd() (and, on Win32, getdcwd()) into the caller's namespace. | ||||
23 | |||||
24 | |||||
25 | =head2 getcwd and friends | ||||
26 | |||||
27 | Each of these functions are called without arguments and return the | ||||
28 | absolute path of the current working directory. | ||||
29 | |||||
30 | =over 4 | ||||
31 | |||||
32 | =item getcwd | ||||
33 | |||||
34 | my $cwd = getcwd(); | ||||
35 | |||||
36 | Returns the current working directory. | ||||
37 | |||||
38 | Exposes the POSIX function getcwd(3) or re-implements it if it's not | ||||
39 | available. | ||||
40 | |||||
41 | =item cwd | ||||
42 | |||||
43 | my $cwd = cwd(); | ||||
44 | |||||
45 | The cwd() is the most natural form for the current architecture. For | ||||
46 | most systems it is identical to `pwd` (but without the trailing line | ||||
47 | terminator). | ||||
48 | |||||
49 | =item fastcwd | ||||
50 | |||||
51 | my $cwd = fastcwd(); | ||||
52 | |||||
53 | A more dangerous version of getcwd(), but potentially faster. | ||||
54 | |||||
55 | It might conceivably chdir() you out of a directory that it can't | ||||
56 | chdir() you back into. If fastcwd encounters a problem it will return | ||||
57 | undef but will probably leave you in a different directory. For a | ||||
58 | measure of extra security, if everything appears to have worked, the | ||||
59 | fastcwd() function will check that it leaves you in the same directory | ||||
60 | that it started in. If it has changed it will C<die> with the message | ||||
61 | "Unstable directory path, current directory changed | ||||
62 | unexpectedly". That should never happen. | ||||
63 | |||||
64 | =item fastgetcwd | ||||
65 | |||||
66 | my $cwd = fastgetcwd(); | ||||
67 | |||||
68 | The fastgetcwd() function is provided as a synonym for cwd(). | ||||
69 | |||||
70 | =item getdcwd | ||||
71 | |||||
72 | my $cwd = getdcwd(); | ||||
73 | my $cwd = getdcwd('C:'); | ||||
74 | |||||
75 | The getdcwd() function is also provided on Win32 to get the current working | ||||
76 | directory on the specified drive, since Windows maintains a separate current | ||||
77 | working directory for each drive. If no drive is specified then the current | ||||
78 | drive is assumed. | ||||
79 | |||||
80 | This function simply calls the Microsoft C library _getdcwd() function. | ||||
81 | |||||
82 | =back | ||||
83 | |||||
84 | |||||
85 | =head2 abs_path and friends | ||||
86 | |||||
87 | These functions are exported only on request. They each take a single | ||||
88 | argument and return the absolute pathname for it. If no argument is | ||||
89 | given they'll use the current working directory. | ||||
90 | |||||
91 | =over 4 | ||||
92 | |||||
93 | =item abs_path | ||||
94 | |||||
95 | my $abs_path = abs_path($file); | ||||
96 | |||||
97 | Uses the same algorithm as getcwd(). Symbolic links and relative-path | ||||
98 | components ("." and "..") are resolved to return the canonical | ||||
99 | pathname, just like realpath(3). | ||||
100 | |||||
101 | =item realpath | ||||
102 | |||||
103 | my $abs_path = realpath($file); | ||||
104 | |||||
105 | A synonym for abs_path(). | ||||
106 | |||||
107 | =item fast_abs_path | ||||
108 | |||||
109 | my $abs_path = fast_abs_path($file); | ||||
110 | |||||
111 | A more dangerous, but potentially faster version of abs_path. | ||||
112 | |||||
113 | =back | ||||
114 | |||||
115 | =head2 $ENV{PWD} | ||||
116 | |||||
117 | If you ask to override your chdir() built-in function, | ||||
118 | |||||
119 | use Cwd qw(chdir); | ||||
120 | |||||
121 | then your PWD environment variable will be kept up to date. Note that | ||||
122 | it will only be kept up to date if all packages which use chdir import | ||||
123 | it from Cwd. | ||||
124 | |||||
125 | |||||
126 | =head1 NOTES | ||||
127 | |||||
128 | =over 4 | ||||
129 | |||||
130 | =item * | ||||
131 | |||||
132 | Since the path separators are different on some operating systems ('/' | ||||
133 | on Unix, ':' on MacPerl, etc...) we recommend you use the File::Spec | ||||
134 | modules wherever portability is a concern. | ||||
135 | |||||
136 | =item * | ||||
137 | |||||
138 | Actually, on Mac OS, the C<getcwd()>, C<fastgetcwd()> and C<fastcwd()> | ||||
139 | functions are all aliases for the C<cwd()> function, which, on Mac OS, | ||||
140 | calls `pwd`. Likewise, the C<abs_path()> function is an alias for | ||||
141 | C<fast_abs_path()>. | ||||
142 | |||||
143 | =back | ||||
144 | |||||
145 | =head1 AUTHOR | ||||
146 | |||||
147 | Originally by the perl5-porters. | ||||
148 | |||||
149 | Maintained by Ken Williams <KWILLIAMS@cpan.org> | ||||
150 | |||||
151 | =head1 COPYRIGHT | ||||
152 | |||||
153 | Copyright (c) 2004 by the Perl 5 Porters. All rights reserved. | ||||
154 | |||||
155 | This program is free software; you can redistribute it and/or modify | ||||
156 | it under the same terms as Perl itself. | ||||
157 | |||||
158 | Portions of the C code in this library are copyright (c) 1994 by the | ||||
159 | Regents of the University of California. All rights reserved. The | ||||
160 | license on this code is compatible with the licensing of the rest of | ||||
161 | the distribution - please see the source code in F<Cwd.xs> for the | ||||
162 | details. | ||||
163 | |||||
164 | =head1 SEE ALSO | ||||
165 | |||||
166 | L<File::chdir> | ||||
167 | |||||
168 | =cut | ||||
169 | |||||
170 | 2 | 0s | 2 | 0s | # spent 0s within Cwd::BEGIN@170 which was called:
# once (0s+0s) by File::Path::BEGIN@6 at line 170 # spent 0s making 1 call to Cwd::BEGIN@170
# spent 0s making 1 call to strict::import |
171 | 2 | 0s | 2 | 0s | # spent 0s within Cwd::BEGIN@171 which was called:
# once (0s+0s) by File::Path::BEGIN@6 at line 171 # spent 0s making 1 call to Cwd::BEGIN@171
# spent 0s making 1 call to Exporter::import |
172 | 2 | 0s | 2 | 0s | # spent 0s within Cwd::BEGIN@172 which was called:
# once (0s+0s) by File::Path::BEGIN@6 at line 172 # spent 0s making 1 call to Cwd::BEGIN@172
# spent 0s making 1 call to vars::import |
173 | |||||
174 | 1 | 0s | $VERSION = '3.48_01'; | ||
175 | 1 | 0s | my $xs_version = $VERSION; | ||
176 | 1 | 0s | $VERSION =~ tr/_//; | ||
177 | |||||
178 | 1 | 0s | @ISA = qw/ Exporter /; | ||
179 | 1 | 0s | @EXPORT = qw(cwd getcwd fastcwd fastgetcwd); | ||
180 | 1 | 0s | push @EXPORT, qw(getdcwd) if $^O eq 'MSWin32'; | ||
181 | 1 | 0s | @EXPORT_OK = qw(chdir abs_path fast_abs_path realpath fast_realpath); | ||
182 | |||||
183 | # sys_cwd may keep the builtin command | ||||
184 | |||||
185 | # All the functionality of this module may provided by builtins, | ||||
186 | # there is no sense to process the rest of the file. | ||||
187 | # The best choice may be to have this in BEGIN, but how to return from BEGIN? | ||||
188 | |||||
189 | 1 | 0s | if ($^O eq 'os2') { | ||
190 | local $^W = 0; | ||||
191 | |||||
192 | *cwd = defined &sys_cwd ? \&sys_cwd : \&_os2_cwd; | ||||
193 | *getcwd = \&cwd; | ||||
194 | *fastgetcwd = \&cwd; | ||||
195 | *fastcwd = \&cwd; | ||||
196 | |||||
197 | *fast_abs_path = \&sys_abspath if defined &sys_abspath; | ||||
198 | *abs_path = \&fast_abs_path; | ||||
199 | *realpath = \&fast_abs_path; | ||||
200 | *fast_realpath = \&fast_abs_path; | ||||
201 | |||||
202 | return 1; | ||||
203 | } | ||||
204 | |||||
205 | # Need to look up the feature settings on VMS. The preferred way is to use the | ||||
206 | # VMS::Feature module, but that may not be available to dual life modules. | ||||
207 | |||||
208 | 1 | 0s | my $use_vms_feature; | ||
209 | # spent 0s within Cwd::BEGIN@209 which was called:
# once (0s+0s) by File::Path::BEGIN@6 at line 215 | ||||
210 | 1 | 0s | if ($^O eq 'VMS') { | ||
211 | if (eval { local $SIG{__DIE__}; require VMS::Feature; }) { | ||||
212 | $use_vms_feature = 1; | ||||
213 | } | ||||
214 | } | ||||
215 | 1 | 0s | 1 | 0s | } # spent 0s making 1 call to Cwd::BEGIN@209 |
216 | |||||
217 | # Need to look up the UNIX report mode. This may become a dynamic mode | ||||
218 | # in the future. | ||||
219 | sub _vms_unix_rpt { | ||||
220 | my $unix_rpt; | ||||
221 | if ($use_vms_feature) { | ||||
222 | $unix_rpt = VMS::Feature::current("filename_unix_report"); | ||||
223 | } else { | ||||
224 | my $env_unix_rpt = $ENV{'DECC$FILENAME_UNIX_REPORT'} || ''; | ||||
225 | $unix_rpt = $env_unix_rpt =~ /^[ET1]/i; | ||||
226 | } | ||||
227 | return $unix_rpt; | ||||
228 | } | ||||
229 | |||||
230 | # Need to look up the EFS character set mode. This may become a dynamic | ||||
231 | # mode in the future. | ||||
232 | sub _vms_efs { | ||||
233 | my $efs; | ||||
234 | if ($use_vms_feature) { | ||||
235 | $efs = VMS::Feature::current("efs_charset"); | ||||
236 | } else { | ||||
237 | my $env_efs = $ENV{'DECC$EFS_CHARSET'} || ''; | ||||
238 | $efs = $env_efs =~ /^[ET1]/i; | ||||
239 | } | ||||
240 | return $efs; | ||||
241 | } | ||||
242 | |||||
243 | |||||
244 | # If loading the XS stuff doesn't work, we can fall back to pure perl | ||||
245 | 1 | 0s | unless (defined &getcwd) { | ||
246 | 1 | 0s | eval { | ||
247 | 1 | 0s | if ( $] >= 5.006 ) { | ||
248 | 1 | 0s | require XSLoader; | ||
249 | 1 | 0s | 1 | 0s | XSLoader::load( __PACKAGE__, $xs_version); # spent 0s making 1 call to XSLoader::load |
250 | } else { | ||||
251 | require DynaLoader; | ||||
252 | push @ISA, 'DynaLoader'; | ||||
253 | __PACKAGE__->bootstrap( $xs_version ); | ||||
254 | } | ||||
255 | }; | ||||
256 | } | ||||
257 | |||||
258 | # Big nasty table of function aliases | ||||
259 | 1 | 0s | my %METHOD_MAP = | ||
260 | ( | ||||
261 | VMS => | ||||
262 | { | ||||
263 | cwd => '_vms_cwd', | ||||
264 | getcwd => '_vms_cwd', | ||||
265 | fastcwd => '_vms_cwd', | ||||
266 | fastgetcwd => '_vms_cwd', | ||||
267 | abs_path => '_vms_abs_path', | ||||
268 | fast_abs_path => '_vms_abs_path', | ||||
269 | }, | ||||
270 | |||||
271 | MSWin32 => | ||||
272 | { | ||||
273 | # We assume that &_NT_cwd is defined as an XSUB or in the core. | ||||
274 | cwd => '_NT_cwd', | ||||
275 | getcwd => '_NT_cwd', | ||||
276 | fastcwd => '_NT_cwd', | ||||
277 | fastgetcwd => '_NT_cwd', | ||||
278 | abs_path => 'fast_abs_path', | ||||
279 | realpath => 'fast_abs_path', | ||||
280 | }, | ||||
281 | |||||
282 | dos => | ||||
283 | { | ||||
284 | cwd => '_dos_cwd', | ||||
285 | getcwd => '_dos_cwd', | ||||
286 | fastgetcwd => '_dos_cwd', | ||||
287 | fastcwd => '_dos_cwd', | ||||
288 | abs_path => 'fast_abs_path', | ||||
289 | }, | ||||
290 | |||||
291 | # QNX4. QNX6 has a $os of 'nto'. | ||||
292 | qnx => | ||||
293 | { | ||||
294 | cwd => '_qnx_cwd', | ||||
295 | getcwd => '_qnx_cwd', | ||||
296 | fastgetcwd => '_qnx_cwd', | ||||
297 | fastcwd => '_qnx_cwd', | ||||
298 | abs_path => '_qnx_abs_path', | ||||
299 | fast_abs_path => '_qnx_abs_path', | ||||
300 | }, | ||||
301 | |||||
302 | cygwin => | ||||
303 | { | ||||
304 | getcwd => 'cwd', | ||||
305 | fastgetcwd => 'cwd', | ||||
306 | fastcwd => 'cwd', | ||||
307 | abs_path => 'fast_abs_path', | ||||
308 | realpath => 'fast_abs_path', | ||||
309 | }, | ||||
310 | |||||
311 | epoc => | ||||
312 | { | ||||
313 | cwd => '_epoc_cwd', | ||||
314 | getcwd => '_epoc_cwd', | ||||
315 | fastgetcwd => '_epoc_cwd', | ||||
316 | fastcwd => '_epoc_cwd', | ||||
317 | abs_path => 'fast_abs_path', | ||||
318 | }, | ||||
319 | |||||
320 | MacOS => | ||||
321 | { | ||||
322 | getcwd => 'cwd', | ||||
323 | fastgetcwd => 'cwd', | ||||
324 | fastcwd => 'cwd', | ||||
325 | abs_path => 'fast_abs_path', | ||||
326 | }, | ||||
327 | ); | ||||
328 | |||||
329 | 1 | 0s | $METHOD_MAP{NT} = $METHOD_MAP{MSWin32}; | ||
330 | |||||
331 | |||||
332 | # Find the pwd command in the expected locations. We assume these | ||||
333 | # are safe. This prevents _backtick_pwd() consulting $ENV{PATH} | ||||
334 | # so everything works under taint mode. | ||||
335 | 1 | 0s | my $pwd_cmd; | ||
336 | 1 | 0s | foreach my $try ('/bin/pwd', | ||
337 | '/usr/bin/pwd', | ||||
338 | '/QOpenSys/bin/pwd', # OS/400 PASE. | ||||
339 | ) { | ||||
340 | |||||
341 | 3 | 0s | 3 | 0s | if( -x $try ) { # spent 0s making 3 calls to Cwd::CORE:fteexec, avg 0s/call |
342 | $pwd_cmd = $try; | ||||
343 | last; | ||||
344 | } | ||||
345 | } | ||||
346 | |||||
347 | # Android has a built-in pwd. Using $pwd_cmd will DTRT if | ||||
348 | # this perl was compiled with -Dd_useshellcmds, which is the | ||||
349 | # default for Android, but the block below is needed for the | ||||
350 | # miniperl running on the host when cross-compiling, and | ||||
351 | # potentially for native builds with -Ud_useshellcmds. | ||||
352 | 1 | 0s | 1 | 0s | if ($^O =~ /android/) { # spent 0s making 1 call to Cwd::CORE:match |
353 | # If targetsh is executable, then we're either a full | ||||
354 | # perl, or a miniperl for a native build. | ||||
355 | if (-x $Config::Config{targetsh}) { | ||||
356 | $pwd_cmd = "$Config::Config{targetsh} -c pwd" | ||||
357 | } | ||||
358 | else { | ||||
359 | my $sh = $Config::Config{sh} || (-x '/system/bin/sh' ? '/system/bin/sh' : 'sh'); | ||||
360 | $pwd_cmd = "$sh -c pwd" | ||||
361 | } | ||||
362 | } | ||||
363 | |||||
364 | 1 | 0s | my $found_pwd_cmd = defined($pwd_cmd); | ||
365 | 1 | 0s | unless ($pwd_cmd) { | ||
366 | # Isn't this wrong? _backtick_pwd() will fail if someone has | ||||
367 | # pwd in their path but it is not /bin/pwd or /usr/bin/pwd? | ||||
368 | # See [perl #16774]. --jhi | ||||
369 | $pwd_cmd = 'pwd'; | ||||
370 | } | ||||
371 | |||||
372 | # Lazy-load Carp | ||||
373 | sub _carp { require Carp; Carp::carp(@_) } | ||||
374 | sub _croak { require Carp; Carp::croak(@_) } | ||||
375 | |||||
376 | # The 'natural and safe form' for UNIX (pwd may be setuid root) | ||||
377 | sub _backtick_pwd { | ||||
378 | # Localize %ENV entries in a way that won't create new hash keys | ||||
379 | my @localize = grep exists $ENV{$_}, qw(PATH IFS CDPATH ENV BASH_ENV); | ||||
380 | local @ENV{@localize}; | ||||
381 | |||||
382 | my $cwd = `$pwd_cmd`; | ||||
383 | # Belt-and-suspenders in case someone said "undef $/". | ||||
384 | local $/ = "\n"; | ||||
385 | # `pwd` may fail e.g. if the disk is full | ||||
386 | chomp($cwd) if defined $cwd; | ||||
387 | $cwd; | ||||
388 | } | ||||
389 | |||||
390 | # Since some ports may predefine cwd internally (e.g., NT) | ||||
391 | # we take care not to override an existing definition for cwd(). | ||||
392 | |||||
393 | 1 | 0s | unless ($METHOD_MAP{$^O}{cwd} or defined &cwd) { | ||
394 | # The pwd command is not available in some chroot(2)'ed environments | ||||
395 | my $sep = $Config::Config{path_sep} || ':'; | ||||
396 | my $os = $^O; # Protect $^O from tainting | ||||
397 | |||||
398 | |||||
399 | # Try again to find a pwd, this time searching the whole PATH. | ||||
400 | if (defined $ENV{PATH} and $os ne 'MSWin32') { # no pwd on Windows | ||||
401 | my @candidates = split($sep, $ENV{PATH}); | ||||
402 | while (!$found_pwd_cmd and @candidates) { | ||||
403 | my $candidate = shift @candidates; | ||||
404 | $found_pwd_cmd = 1 if -x "$candidate/pwd"; | ||||
405 | } | ||||
406 | } | ||||
407 | |||||
408 | # MacOS has some special magic to make `pwd` work. | ||||
409 | if( $os eq 'MacOS' || $found_pwd_cmd ) | ||||
410 | { | ||||
411 | *cwd = \&_backtick_pwd; | ||||
412 | } | ||||
413 | else { | ||||
414 | *cwd = \&getcwd; | ||||
415 | } | ||||
416 | } | ||||
417 | |||||
418 | 1 | 0s | if ($^O eq 'cygwin') { | ||
419 | # We need to make sure cwd() is called with no args, because it's | ||||
420 | # got an arg-less prototype and will die if args are present. | ||||
421 | local $^W = 0; | ||||
422 | my $orig_cwd = \&cwd; | ||||
423 | *cwd = sub { &$orig_cwd() } | ||||
424 | } | ||||
425 | |||||
426 | |||||
427 | # set a reasonable (and very safe) default for fastgetcwd, in case it | ||||
428 | # isn't redefined later (20001212 rspier) | ||||
429 | 1 | 0s | *fastgetcwd = \&cwd; | ||
430 | |||||
431 | # A non-XS version of getcwd() - also used to bootstrap the perl build | ||||
432 | # process, when miniperl is running and no XS loading happens. | ||||
433 | sub _perl_getcwd | ||||
434 | { | ||||
435 | abs_path('.'); | ||||
436 | } | ||||
437 | |||||
438 | # By John Bazik | ||||
439 | # | ||||
440 | # Usage: $cwd = &fastcwd; | ||||
441 | # | ||||
442 | # This is a faster version of getcwd. It's also more dangerous because | ||||
443 | # you might chdir out of a directory that you can't chdir back into. | ||||
444 | |||||
445 | sub fastcwd_ { | ||||
446 | my($odev, $oino, $cdev, $cino, $tdev, $tino); | ||||
447 | my(@path, $path); | ||||
448 | local(*DIR); | ||||
449 | |||||
450 | my($orig_cdev, $orig_cino) = stat('.'); | ||||
451 | ($cdev, $cino) = ($orig_cdev, $orig_cino); | ||||
452 | for (;;) { | ||||
453 | my $direntry; | ||||
454 | ($odev, $oino) = ($cdev, $cino); | ||||
455 | CORE::chdir('..') || return undef; | ||||
456 | ($cdev, $cino) = stat('.'); | ||||
457 | last if $odev == $cdev && $oino == $cino; | ||||
458 | opendir(DIR, '.') || return undef; | ||||
459 | for (;;) { | ||||
460 | $direntry = readdir(DIR); | ||||
461 | last unless defined $direntry; | ||||
462 | next if $direntry eq '.'; | ||||
463 | next if $direntry eq '..'; | ||||
464 | |||||
465 | ($tdev, $tino) = lstat($direntry); | ||||
466 | last unless $tdev != $odev || $tino != $oino; | ||||
467 | } | ||||
468 | closedir(DIR); | ||||
469 | return undef unless defined $direntry; # should never happen | ||||
470 | unshift(@path, $direntry); | ||||
471 | } | ||||
472 | $path = '/' . join('/', @path); | ||||
473 | if ($^O eq 'apollo') { $path = "/".$path; } | ||||
474 | # At this point $path may be tainted (if tainting) and chdir would fail. | ||||
475 | # Untaint it then check that we landed where we started. | ||||
476 | $path =~ /^(.*)\z/s # untaint | ||||
477 | && CORE::chdir($1) or return undef; | ||||
478 | ($cdev, $cino) = stat('.'); | ||||
479 | die "Unstable directory path, current directory changed unexpectedly" | ||||
480 | if $cdev != $orig_cdev || $cino != $orig_cino; | ||||
481 | $path; | ||||
482 | } | ||||
483 | 1 | 0s | if (not defined &fastcwd) { *fastcwd = \&fastcwd_ } | ||
484 | |||||
485 | |||||
486 | # Keeps track of current working directory in PWD environment var | ||||
487 | # Usage: | ||||
488 | # use Cwd 'chdir'; | ||||
489 | # chdir $newdir; | ||||
490 | |||||
491 | 1 | 0s | my $chdir_init = 0; | ||
492 | |||||
493 | sub chdir_init { | ||||
494 | if ($ENV{'PWD'} and $^O ne 'os2' and $^O ne 'dos' and $^O ne 'MSWin32') { | ||||
495 | my($dd,$di) = stat('.'); | ||||
496 | my($pd,$pi) = stat($ENV{'PWD'}); | ||||
497 | if (!defined $dd or !defined $pd or $di != $pi or $dd != $pd) { | ||||
498 | $ENV{'PWD'} = cwd(); | ||||
499 | } | ||||
500 | } | ||||
501 | else { | ||||
502 | my $wd = cwd(); | ||||
503 | $wd = Win32::GetFullPathName($wd) if $^O eq 'MSWin32'; | ||||
504 | $ENV{'PWD'} = $wd; | ||||
505 | } | ||||
506 | # Strip an automounter prefix (where /tmp_mnt/foo/bar == /foo/bar) | ||||
507 | if ($^O ne 'MSWin32' and $ENV{'PWD'} =~ m|(/[^/]+(/[^/]+/[^/]+))(.*)|s) { | ||||
508 | my($pd,$pi) = stat($2); | ||||
509 | my($dd,$di) = stat($1); | ||||
510 | if (defined $pd and defined $dd and $di == $pi and $dd == $pd) { | ||||
511 | $ENV{'PWD'}="$2$3"; | ||||
512 | } | ||||
513 | } | ||||
514 | $chdir_init = 1; | ||||
515 | } | ||||
516 | |||||
517 | sub chdir { | ||||
518 | my $newdir = @_ ? shift : ''; # allow for no arg (chdir to HOME dir) | ||||
519 | $newdir =~ s|///*|/|g unless $^O eq 'MSWin32'; | ||||
520 | chdir_init() unless $chdir_init; | ||||
521 | my $newpwd; | ||||
522 | if ($^O eq 'MSWin32') { | ||||
523 | # get the full path name *before* the chdir() | ||||
524 | $newpwd = Win32::GetFullPathName($newdir); | ||||
525 | } | ||||
526 | |||||
527 | return 0 unless CORE::chdir $newdir; | ||||
528 | |||||
529 | if ($^O eq 'VMS') { | ||||
530 | return $ENV{'PWD'} = $ENV{'DEFAULT'} | ||||
531 | } | ||||
532 | elsif ($^O eq 'MacOS') { | ||||
533 | return $ENV{'PWD'} = cwd(); | ||||
534 | } | ||||
535 | elsif ($^O eq 'MSWin32') { | ||||
536 | $ENV{'PWD'} = $newpwd; | ||||
537 | return 1; | ||||
538 | } | ||||
539 | |||||
540 | if (ref $newdir eq 'GLOB') { # in case a file/dir handle is passed in | ||||
541 | $ENV{'PWD'} = cwd(); | ||||
542 | } elsif ($newdir =~ m#^/#s) { | ||||
543 | $ENV{'PWD'} = $newdir; | ||||
544 | } else { | ||||
545 | my @curdir = split(m#/#,$ENV{'PWD'}); | ||||
546 | @curdir = ('') unless @curdir; | ||||
547 | my $component; | ||||
548 | foreach $component (split(m#/#, $newdir)) { | ||||
549 | next if $component eq '.'; | ||||
550 | pop(@curdir),next if $component eq '..'; | ||||
551 | push(@curdir,$component); | ||||
552 | } | ||||
553 | $ENV{'PWD'} = join('/',@curdir) || '/'; | ||||
554 | } | ||||
555 | 1; | ||||
556 | } | ||||
557 | |||||
558 | |||||
559 | sub _perl_abs_path | ||||
560 | { | ||||
561 | my $start = @_ ? shift : '.'; | ||||
562 | my($dotdots, $cwd, @pst, @cst, $dir, @tst); | ||||
563 | |||||
564 | unless (@cst = stat( $start )) | ||||
565 | { | ||||
566 | _carp("stat($start): $!"); | ||||
567 | return ''; | ||||
568 | } | ||||
569 | |||||
570 | unless (-d _) { | ||||
571 | # Make sure we can be invoked on plain files, not just directories. | ||||
572 | # NOTE that this routine assumes that '/' is the only directory separator. | ||||
573 | |||||
574 | my ($dir, $file) = $start =~ m{^(.*)/(.+)$} | ||||
575 | or return cwd() . '/' . $start; | ||||
576 | |||||
577 | # Can't use "-l _" here, because the previous stat was a stat(), not an lstat(). | ||||
578 | if (-l $start) { | ||||
579 | my $link_target = readlink($start); | ||||
580 | die "Can't resolve link $start: $!" unless defined $link_target; | ||||
581 | |||||
582 | require File::Spec; | ||||
583 | $link_target = $dir . '/' . $link_target | ||||
584 | unless File::Spec->file_name_is_absolute($link_target); | ||||
585 | |||||
586 | return abs_path($link_target); | ||||
587 | } | ||||
588 | |||||
589 | return $dir ? abs_path($dir) . "/$file" : "/$file"; | ||||
590 | } | ||||
591 | |||||
592 | $cwd = ''; | ||||
593 | $dotdots = $start; | ||||
594 | do | ||||
595 | { | ||||
596 | $dotdots .= '/..'; | ||||
597 | @pst = @cst; | ||||
598 | local *PARENT; | ||||
599 | unless (opendir(PARENT, $dotdots)) | ||||
600 | { | ||||
601 | # probably a permissions issue. Try the native command. | ||||
602 | require File::Spec; | ||||
603 | return File::Spec->rel2abs( $start, _backtick_pwd() ); | ||||
604 | } | ||||
605 | unless (@cst = stat($dotdots)) | ||||
606 | { | ||||
607 | _carp("stat($dotdots): $!"); | ||||
608 | closedir(PARENT); | ||||
609 | return ''; | ||||
610 | } | ||||
611 | if ($pst[0] == $cst[0] && $pst[1] == $cst[1]) | ||||
612 | { | ||||
613 | $dir = undef; | ||||
614 | } | ||||
615 | else | ||||
616 | { | ||||
617 | do | ||||
618 | { | ||||
619 | unless (defined ($dir = readdir(PARENT))) | ||||
620 | { | ||||
621 | _carp("readdir($dotdots): $!"); | ||||
622 | closedir(PARENT); | ||||
623 | return ''; | ||||
624 | } | ||||
625 | $tst[0] = $pst[0]+1 unless (@tst = lstat("$dotdots/$dir")) | ||||
626 | } | ||||
627 | while ($dir eq '.' || $dir eq '..' || $tst[0] != $pst[0] || | ||||
628 | $tst[1] != $pst[1]); | ||||
629 | } | ||||
630 | $cwd = (defined $dir ? "$dir" : "" ) . "/$cwd" ; | ||||
631 | closedir(PARENT); | ||||
632 | } while (defined $dir); | ||||
633 | chop($cwd) unless $cwd eq '/'; # drop the trailing / | ||||
634 | $cwd; | ||||
635 | } | ||||
636 | |||||
637 | |||||
638 | 1 | 0s | my $Curdir; | ||
639 | # spent 0s within Cwd::fast_abs_path which was called 5 times, avg 0s/call:
# 5 times (0s+0s) by ExtUtils::MakeMaker::eval_in_subdirs at line 223 of ExtUtils/MakeMaker.pm, avg 0s/call | ||||
640 | 5 | 0s | local $ENV{PWD} = $ENV{PWD} || ''; # Guard against clobberage | ||
641 | 5 | 0s | 5 | 0s | my $cwd = getcwd(); # spent 0s making 5 calls to Cwd::_win32_cwd, avg 0s/call |
642 | 5 | 0s | require File::Spec; | ||
643 | 5 | 0s | my $path = @_ ? shift : ($Curdir ||= File::Spec->curdir); | ||
644 | |||||
645 | # Detaint else we'll explode in taint mode. This is safe because | ||||
646 | # we're not doing anything dangerous with it. | ||||
647 | 5 | 0s | 5 | 0s | ($path) = $path =~ /(.*)/s; # spent 0s making 5 calls to Cwd::CORE:match, avg 0s/call |
648 | 5 | 0s | 5 | 0s | ($cwd) = $cwd =~ /(.*)/s; # spent 0s making 5 calls to Cwd::CORE:match, avg 0s/call |
649 | |||||
650 | 5 | 0s | 5 | 0s | unless (-e $path) { # spent 0s making 5 calls to Cwd::CORE:ftis, avg 0s/call |
651 | _croak("$path: No such file or directory"); | ||||
652 | } | ||||
653 | |||||
654 | 5 | 0s | 5 | 0s | unless (-d _) { # spent 0s making 5 calls to Cwd::CORE:ftdir, avg 0s/call |
655 | # Make sure we can be invoked on plain files, not just directories. | ||||
656 | |||||
657 | my ($vol, $dir, $file) = File::Spec->splitpath($path); | ||||
658 | return File::Spec->catfile($cwd, $path) unless length $dir; | ||||
659 | |||||
660 | if (-l $path) { | ||||
661 | my $link_target = readlink($path); | ||||
662 | die "Can't resolve link $path: $!" unless defined $link_target; | ||||
663 | |||||
664 | $link_target = File::Spec->catpath($vol, $dir, $link_target) | ||||
665 | unless File::Spec->file_name_is_absolute($link_target); | ||||
666 | |||||
667 | return fast_abs_path($link_target); | ||||
668 | } | ||||
669 | |||||
670 | return $dir eq File::Spec->rootdir | ||||
671 | ? File::Spec->catpath($vol, $dir, $file) | ||||
672 | : fast_abs_path(File::Spec->catpath($vol, $dir, '')) . '/' . $file; | ||||
673 | } | ||||
674 | |||||
675 | 5 | 0s | 5 | 0s | if (!CORE::chdir($path)) { # spent 0s making 5 calls to Cwd::CORE:chdir, avg 0s/call |
676 | _croak("Cannot chdir to $path: $!"); | ||||
677 | } | ||||
678 | 5 | 0s | 5 | 0s | my $realpath = getcwd(); # spent 0s making 5 calls to Cwd::_win32_cwd, avg 0s/call |
679 | 5 | 0s | 10 | 0s | if (! ((-d $cwd) && (CORE::chdir($cwd)))) { # spent 0s making 5 calls to Cwd::CORE:chdir, avg 0s/call
# spent 0s making 5 calls to Cwd::CORE:ftdir, avg 0s/call |
680 | _croak("Cannot chdir back to $cwd: $!"); | ||||
681 | } | ||||
682 | 5 | 0s | $realpath; | ||
683 | } | ||||
684 | |||||
685 | # added function alias to follow principle of least surprise | ||||
686 | # based on previous aliasing. --tchrist 27-Jan-00 | ||||
687 | 1 | 0s | *fast_realpath = \&fast_abs_path; | ||
688 | |||||
689 | |||||
690 | # --- PORTING SECTION --- | ||||
691 | |||||
692 | # VMS: $ENV{'DEFAULT'} points to default directory at all times | ||||
693 | # 06-Mar-1996 Charles Bailey bailey@newman.upenn.edu | ||||
694 | # Note: Use of Cwd::chdir() causes the logical name PWD to be defined | ||||
695 | # in the process logical name table as the default device and directory | ||||
696 | # seen by Perl. This may not be the same as the default device | ||||
697 | # and directory seen by DCL after Perl exits, since the effects | ||||
698 | # the CRTL chdir() function persist only until Perl exits. | ||||
699 | |||||
700 | sub _vms_cwd { | ||||
701 | return $ENV{'DEFAULT'}; | ||||
702 | } | ||||
703 | |||||
704 | sub _vms_abs_path { | ||||
705 | return $ENV{'DEFAULT'} unless @_; | ||||
706 | my $path = shift; | ||||
707 | |||||
708 | my $efs = _vms_efs; | ||||
709 | my $unix_rpt = _vms_unix_rpt; | ||||
710 | |||||
711 | if (defined &VMS::Filespec::vmsrealpath) { | ||||
712 | my $path_unix = 0; | ||||
713 | my $path_vms = 0; | ||||
714 | |||||
715 | $path_unix = 1 if ($path =~ m#(?<=\^)/#); | ||||
716 | $path_unix = 1 if ($path =~ /^\.\.?$/); | ||||
717 | $path_vms = 1 if ($path =~ m#[\[<\]]#); | ||||
718 | $path_vms = 1 if ($path =~ /^--?$/); | ||||
719 | |||||
720 | my $unix_mode = $path_unix; | ||||
721 | if ($efs) { | ||||
722 | # In case of a tie, the Unix report mode decides. | ||||
723 | if ($path_vms == $path_unix) { | ||||
724 | $unix_mode = $unix_rpt; | ||||
725 | } else { | ||||
726 | $unix_mode = 0 if $path_vms; | ||||
727 | } | ||||
728 | } | ||||
729 | |||||
730 | if ($unix_mode) { | ||||
731 | # Unix format | ||||
732 | return VMS::Filespec::unixrealpath($path); | ||||
733 | } | ||||
734 | |||||
735 | # VMS format | ||||
736 | |||||
737 | my $new_path = VMS::Filespec::vmsrealpath($path); | ||||
738 | |||||
739 | # Perl expects directories to be in directory format | ||||
740 | $new_path = VMS::Filespec::pathify($new_path) if -d $path; | ||||
741 | return $new_path; | ||||
742 | } | ||||
743 | |||||
744 | # Fallback to older algorithm if correct ones are not | ||||
745 | # available. | ||||
746 | |||||
747 | if (-l $path) { | ||||
748 | my $link_target = readlink($path); | ||||
749 | die "Can't resolve link $path: $!" unless defined $link_target; | ||||
750 | |||||
751 | return _vms_abs_path($link_target); | ||||
752 | } | ||||
753 | |||||
754 | # may need to turn foo.dir into [.foo] | ||||
755 | my $pathified = VMS::Filespec::pathify($path); | ||||
756 | $path = $pathified if defined $pathified; | ||||
757 | |||||
758 | return VMS::Filespec::rmsexpand($path); | ||||
759 | } | ||||
760 | |||||
761 | sub _os2_cwd { | ||||
762 | $ENV{'PWD'} = `cmd /c cd`; | ||||
763 | chomp $ENV{'PWD'}; | ||||
764 | $ENV{'PWD'} =~ s:\\:/:g ; | ||||
765 | return $ENV{'PWD'}; | ||||
766 | } | ||||
767 | |||||
768 | sub _win32_cwd_simple { | ||||
769 | $ENV{'PWD'} = `cd`; | ||||
770 | chomp $ENV{'PWD'}; | ||||
771 | $ENV{'PWD'} =~ s:\\:/:g ; | ||||
772 | return $ENV{'PWD'}; | ||||
773 | } | ||||
774 | |||||
775 | # spent 0s within Cwd::_win32_cwd which was called 15 times, avg 0s/call:
# 5 times (0s+0s) by Cwd::fast_abs_path at line 641, avg 0s/call
# 5 times (0s+0s) by Cwd::fast_abs_path at line 678, avg 0s/call
# 3 times (0s+0s) by ExtUtils::Liblist::Kid::_win32_ext at line 288 of ExtUtils/Liblist/Kid.pm, avg 0s/call
# once (0s+0s) by ExtUtils::MakeMaker::eval_in_subdirs at line 221 of ExtUtils/MakeMaker.pm
# once (0s+0s) by File::Find::_find_opt at line 484 of File/Find.pm | ||||
776 | # Need to avoid taking any sort of reference to the typeglob or the code in | ||||
777 | # the optree, so that this tests the runtime state of things, as the | ||||
778 | # ExtUtils::MakeMaker tests for "miniperl" need to be able to fake things at | ||||
779 | # runtime by deleting the subroutine. *foo{THING} syntax on a symbol table | ||||
780 | # lookup avoids needing a string eval, which has been reported to cause | ||||
781 | # problems (for reasons that we haven't been able to get to the bottom of - | ||||
782 | # rt.cpan.org #56225) | ||||
783 | 15 | 0s | 15 | 0s | if (*{$DynaLoader::{boot_DynaLoader}}{CODE}) { # spent 0s making 15 calls to Win32::GetCwd, avg 0s/call |
784 | $ENV{'PWD'} = Win32::GetCwd(); | ||||
785 | } | ||||
786 | else { # miniperl | ||||
787 | chomp($ENV{'PWD'} = `cd`); | ||||
788 | } | ||||
789 | 15 | 0s | 15 | 0s | $ENV{'PWD'} =~ s:\\:/:g ; # spent 0s making 15 calls to Cwd::CORE:subst, avg 0s/call |
790 | 15 | 0s | return $ENV{'PWD'}; | ||
791 | } | ||||
792 | |||||
793 | 1 | 0s | *_NT_cwd = defined &Win32::GetCwd ? \&_win32_cwd : \&_win32_cwd_simple; | ||
794 | |||||
795 | sub _dos_cwd { | ||||
796 | if (!defined &Dos::GetCwd) { | ||||
797 | $ENV{'PWD'} = `command /c cd`; | ||||
798 | chomp $ENV{'PWD'}; | ||||
799 | $ENV{'PWD'} =~ s:\\:/:g ; | ||||
800 | } else { | ||||
801 | $ENV{'PWD'} = Dos::GetCwd(); | ||||
802 | } | ||||
803 | return $ENV{'PWD'}; | ||||
804 | } | ||||
805 | |||||
806 | sub _qnx_cwd { | ||||
807 | local $ENV{PATH} = ''; | ||||
808 | local $ENV{CDPATH} = ''; | ||||
809 | local $ENV{ENV} = ''; | ||||
810 | $ENV{'PWD'} = `/usr/bin/fullpath -t`; | ||||
811 | chomp $ENV{'PWD'}; | ||||
812 | return $ENV{'PWD'}; | ||||
813 | } | ||||
814 | |||||
815 | sub _qnx_abs_path { | ||||
816 | local $ENV{PATH} = ''; | ||||
817 | local $ENV{CDPATH} = ''; | ||||
818 | local $ENV{ENV} = ''; | ||||
819 | my $path = @_ ? shift : '.'; | ||||
820 | local *REALPATH; | ||||
821 | |||||
822 | defined( open(REALPATH, '-|') || exec '/usr/bin/fullpath', '-t', $path ) or | ||||
823 | die "Can't open /usr/bin/fullpath: $!"; | ||||
824 | my $realpath = <REALPATH>; | ||||
825 | close REALPATH; | ||||
826 | chomp $realpath; | ||||
827 | return $realpath; | ||||
828 | } | ||||
829 | |||||
830 | sub _epoc_cwd { | ||||
831 | $ENV{'PWD'} = EPOC::getcwd(); | ||||
832 | return $ENV{'PWD'}; | ||||
833 | } | ||||
834 | |||||
835 | |||||
836 | # Now that all the base-level functions are set up, alias the | ||||
837 | # user-level functions to the right places | ||||
838 | |||||
839 | 1 | 0s | if (exists $METHOD_MAP{$^O}) { | ||
840 | 1 | 0s | my $map = $METHOD_MAP{$^O}; | ||
841 | 1 | 0s | foreach my $name (keys %$map) { | ||
842 | 6 | 0s | local $^W = 0; # assignments trigger 'subroutine redefined' warning | ||
843 | 2 | 0s | 2 | 0s | # spent 0s within Cwd::BEGIN@843 which was called:
# once (0s+0s) by File::Path::BEGIN@6 at line 843 # spent 0s making 1 call to Cwd::BEGIN@843
# spent 0s making 1 call to strict::unimport |
844 | 6 | 0s | *{$name} = \&{$map->{$name}}; | ||
845 | } | ||||
846 | } | ||||
847 | |||||
848 | # In case the XS version doesn't load. | ||||
849 | 1 | 0s | *abs_path = \&_perl_abs_path unless defined &abs_path; | ||
850 | 1 | 0s | *getcwd = \&_perl_getcwd unless defined &getcwd; | ||
851 | |||||
852 | # added function alias for those of us more | ||||
853 | # used to the libc function. --tchrist 27-Jan-00 | ||||
854 | 1 | 0s | *realpath = \&abs_path; | ||
855 | |||||
856 | 1 | 0s | 1; | ||
sub Cwd::CORE:chdir; # opcode | |||||
sub Cwd::CORE:ftdir; # opcode | |||||
# spent 0s within Cwd::CORE:fteexec which was called 3 times, avg 0s/call:
# 3 times (0s+0s) by File::Path::BEGIN@6 at line 341, avg 0s/call | |||||
# spent 0s within Cwd::CORE:ftis which was called 5 times, avg 0s/call:
# 5 times (0s+0s) by Cwd::fast_abs_path at line 650, avg 0s/call | |||||
sub Cwd::CORE:match; # opcode | |||||
# spent 0s within Cwd::CORE:subst which was called 15 times, avg 0s/call:
# 15 times (0s+0s) by Cwd::_win32_cwd at line 789, avg 0s/call |