blob: a3214ba715dfbbe2699f2fcbde342eab7194dacb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# By Brandon S. Allbery
#
# Usage: $cwd = &getcwd;
sub getcwd
{
local($dotdots, $cwd, @pst, @cst, $dir, @tst);
unless (@cst = stat('.'))
{
warn "stat(.): $!";
return '';
}
$cwd = '';
do
{
$dotdots .= '/' if $dotdots;
$dotdots .= '..';
@pst = @cst;
unless (opendir(getcwd'PARENT, $dotdots)) #'))
{
warn "opendir($dotdots): $!";
return '';
}
unless (@cst = stat($dotdots))
{
warn "stat($dotdots): $!";
closedir(getcwd'PARENT); #');
return '';
}
if ($pst[$[] == $cst[$[] && $pst[$[ + 1] == $cst[$[ + 1])
{
$dir = '';
}
else
{
do
{
unless ($dir = readdir(getcwd'PARENT)) #'))
{
warn "readdir($dotdots): $!";
closedir(getcwd'PARENT); #');
return '';
}
unless (@tst = lstat("$dotdots/$dir"))
{
warn "lstat($dotdots/$dir): $!";
closedir(getcwd'PARENT); #');
return '';
}
}
while ($dir eq '.' || $dir eq '..' || $tst[$[] != $pst[$[] ||
$tst[$[ + 1] != $pst[$[ + 1]);
}
$cwd = "$dir/$cwd";
closedir(getcwd'PARENT); #');
} while ($dir);
chop($cwd);
$cwd;
}
1;
|