line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# By Brandon S. Allbery |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# This library is no longer being maintained, and is included for backward |
4
|
|
|
|
|
|
|
# compatibility with Perl 4 programs which may require it. |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# In particular, this should not be used as an example of modern Perl |
7
|
|
|
|
|
|
|
# programming techniques. |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# Suggested alternative: Cwd |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
# |
12
|
|
|
|
|
|
|
# Usage: $cwd = &getcwd; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub getcwd |
15
|
|
|
|
|
|
|
{ |
16
|
0
|
|
|
0
|
|
|
local($dotdots, $cwd, @pst, @cst, $dir, @tst); |
17
|
|
|
|
|
|
|
|
18
|
0
|
0
|
|
|
|
|
unless (@cst = stat('.')) |
19
|
|
|
|
|
|
|
{ |
20
|
0
|
|
|
|
|
|
warn "stat(.): $!"; |
21
|
0
|
|
|
|
|
|
return ''; |
22
|
|
|
|
|
|
|
} |
23
|
0
|
|
|
|
|
|
$cwd = ''; |
24
|
|
|
|
|
|
|
do |
25
|
0
|
|
|
|
|
|
{ |
26
|
0
|
0
|
|
|
|
|
$dotdots .= '/' if $dotdots; |
27
|
0
|
|
|
|
|
|
$dotdots .= '..'; |
28
|
0
|
|
|
|
|
|
@pst = @cst; |
29
|
0
|
0
|
|
|
|
|
unless (opendir(getcwd::PARENT, $dotdots)) |
30
|
|
|
|
|
|
|
{ |
31
|
0
|
|
|
|
|
|
warn "opendir($dotdots): $!"; |
32
|
0
|
|
|
|
|
|
return ''; |
33
|
|
|
|
|
|
|
} |
34
|
0
|
0
|
|
|
|
|
unless (@cst = stat($dotdots)) |
35
|
|
|
|
|
|
|
{ |
36
|
0
|
|
|
|
|
|
warn "stat($dotdots): $!"; |
37
|
0
|
|
|
|
|
|
closedir(getcwd::PARENT); |
38
|
0
|
|
|
|
|
|
return ''; |
39
|
|
|
|
|
|
|
} |
40
|
0
|
0
|
0
|
|
|
|
if ($pst[0] == $cst[0] && $pst[1] == $cst[1]) |
41
|
|
|
|
|
|
|
{ |
42
|
0
|
|
|
|
|
|
$dir = ''; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
else |
45
|
|
|
|
|
|
|
{ |
46
|
|
|
|
|
|
|
do |
47
|
0
|
|
0
|
|
|
|
{ |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
48
|
0
|
0
|
|
|
|
|
unless (defined ($dir = readdir(getcwd::PARENT))) |
49
|
|
|
|
|
|
|
{ |
50
|
0
|
|
|
|
|
|
warn "readdir($dotdots): $!"; |
51
|
0
|
|
|
|
|
|
closedir(getcwd::PARENT); |
52
|
0
|
|
|
|
|
|
return ''; |
53
|
|
|
|
|
|
|
} |
54
|
0
|
0
|
|
|
|
|
unless (@tst = lstat("$dotdots/$dir")) |
55
|
|
|
|
|
|
|
{ |
56
|
|
|
|
|
|
|
# warn "lstat($dotdots/$dir): $!"; |
57
|
|
|
|
|
|
|
# closedir(getcwd::PARENT); |
58
|
|
|
|
|
|
|
# return ''; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
while ($dir eq '.' || $dir eq '..' || $tst[0] != $pst[0] || |
62
|
|
|
|
|
|
|
$tst[1] != $pst[1]); |
63
|
|
|
|
|
|
|
} |
64
|
0
|
|
|
|
|
|
$cwd = "$dir/$cwd"; |
65
|
0
|
|
|
|
|
|
closedir(getcwd::PARENT); |
66
|
|
|
|
|
|
|
} while ($dir ne ''); |
67
|
0
|
|
|
|
|
|
chop($cwd); |
68
|
0
|
|
|
|
|
|
$cwd; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |