xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/lib/File/Spec/Unix.pm (revision 0:68f95e015346)
1*0Sstevel@tonic-gatepackage File::Spec::Unix;
2*0Sstevel@tonic-gate
3*0Sstevel@tonic-gateuse strict;
4*0Sstevel@tonic-gateuse vars qw($VERSION);
5*0Sstevel@tonic-gate
6*0Sstevel@tonic-gate$VERSION = '1.5';
7*0Sstevel@tonic-gate
8*0Sstevel@tonic-gate=head1 NAME
9*0Sstevel@tonic-gate
10*0Sstevel@tonic-gateFile::Spec::Unix - File::Spec for Unix, base for other File::Spec modules
11*0Sstevel@tonic-gate
12*0Sstevel@tonic-gate=head1 SYNOPSIS
13*0Sstevel@tonic-gate
14*0Sstevel@tonic-gate require File::Spec::Unix; # Done automatically by File::Spec
15*0Sstevel@tonic-gate
16*0Sstevel@tonic-gate=head1 DESCRIPTION
17*0Sstevel@tonic-gate
18*0Sstevel@tonic-gateMethods for manipulating file specifications.  Other File::Spec
19*0Sstevel@tonic-gatemodules, such as File::Spec::Mac, inherit from File::Spec::Unix and
20*0Sstevel@tonic-gateoverride specific methods.
21*0Sstevel@tonic-gate
22*0Sstevel@tonic-gate=head1 METHODS
23*0Sstevel@tonic-gate
24*0Sstevel@tonic-gate=over 2
25*0Sstevel@tonic-gate
26*0Sstevel@tonic-gate=item canonpath()
27*0Sstevel@tonic-gate
28*0Sstevel@tonic-gateNo physical check on the filesystem, but a logical cleanup of a
29*0Sstevel@tonic-gatepath. On UNIX eliminates successive slashes and successive "/.".
30*0Sstevel@tonic-gate
31*0Sstevel@tonic-gate    $cpath = File::Spec->canonpath( $path ) ;
32*0Sstevel@tonic-gate
33*0Sstevel@tonic-gate=cut
34*0Sstevel@tonic-gate
35*0Sstevel@tonic-gatesub canonpath {
36*0Sstevel@tonic-gate    my ($self,$path) = @_;
37*0Sstevel@tonic-gate
38*0Sstevel@tonic-gate    # Handle POSIX-style node names beginning with double slash (qnx, nto)
39*0Sstevel@tonic-gate    # Handle network path names beginning with double slash (cygwin)
40*0Sstevel@tonic-gate    # (POSIX says: "a pathname that begins with two successive slashes
41*0Sstevel@tonic-gate    # may be interpreted in an implementation-defined manner, although
42*0Sstevel@tonic-gate    # more than two leading slashes shall be treated as a single slash.")
43*0Sstevel@tonic-gate    my $node = '';
44*0Sstevel@tonic-gate    if ( $^O =~ m/^(?:qnx|nto|cygwin)$/ && $path =~ s:^(//[^/]+)(/|\z):/:s ) {
45*0Sstevel@tonic-gate      $node = $1;
46*0Sstevel@tonic-gate    }
47*0Sstevel@tonic-gate    # This used to be
48*0Sstevel@tonic-gate    # $path =~ s|/+|/|g unless($^O eq 'cygwin');
49*0Sstevel@tonic-gate    # but that made tests 29, 30, 35, 46, and 213 (as of #13272) to fail
50*0Sstevel@tonic-gate    # (Mainly because trailing "" directories didn't get stripped).
51*0Sstevel@tonic-gate    # Why would cygwin avoid collapsing multiple slashes into one? --jhi
52*0Sstevel@tonic-gate    $path =~ s|/+|/|g;                             # xx////xx  -> xx/xx
53*0Sstevel@tonic-gate    $path =~ s@(/\.)+(/|\Z(?!\n))@/@g;             # xx/././xx -> xx/xx
54*0Sstevel@tonic-gate    $path =~ s|^(\./)+||s unless $path eq "./";    # ./xx      -> xx
55*0Sstevel@tonic-gate    $path =~ s|^/(\.\./)+|/|s;                     # /../../xx -> xx
56*0Sstevel@tonic-gate    $path =~ s|/\Z(?!\n)|| unless $path eq "/";          # xx/       -> xx
57*0Sstevel@tonic-gate    return "$node$path";
58*0Sstevel@tonic-gate}
59*0Sstevel@tonic-gate
60*0Sstevel@tonic-gate=item catdir()
61*0Sstevel@tonic-gate
62*0Sstevel@tonic-gateConcatenate two or more directory names to form a complete path ending
63*0Sstevel@tonic-gatewith a directory. But remove the trailing slash from the resulting
64*0Sstevel@tonic-gatestring, because it doesn't look good, isn't necessary and confuses
65*0Sstevel@tonic-gateOS2. Of course, if this is the root directory, don't cut off the
66*0Sstevel@tonic-gatetrailing slash :-)
67*0Sstevel@tonic-gate
68*0Sstevel@tonic-gate=cut
69*0Sstevel@tonic-gate
70*0Sstevel@tonic-gatesub catdir {
71*0Sstevel@tonic-gate    my $self = shift;
72*0Sstevel@tonic-gate
73*0Sstevel@tonic-gate    $self->canonpath(join('/', @_, '')); # '' because need a trailing '/'
74*0Sstevel@tonic-gate}
75*0Sstevel@tonic-gate
76*0Sstevel@tonic-gate=item catfile
77*0Sstevel@tonic-gate
78*0Sstevel@tonic-gateConcatenate one or more directory names and a filename to form a
79*0Sstevel@tonic-gatecomplete path ending with a filename
80*0Sstevel@tonic-gate
81*0Sstevel@tonic-gate=cut
82*0Sstevel@tonic-gate
83*0Sstevel@tonic-gatesub catfile {
84*0Sstevel@tonic-gate    my $self = shift;
85*0Sstevel@tonic-gate    my $file = $self->canonpath(pop @_);
86*0Sstevel@tonic-gate    return $file unless @_;
87*0Sstevel@tonic-gate    my $dir = $self->catdir(@_);
88*0Sstevel@tonic-gate    $dir .= "/" unless substr($dir,-1) eq "/";
89*0Sstevel@tonic-gate    return $dir.$file;
90*0Sstevel@tonic-gate}
91*0Sstevel@tonic-gate
92*0Sstevel@tonic-gate=item curdir
93*0Sstevel@tonic-gate
94*0Sstevel@tonic-gateReturns a string representation of the current directory.  "." on UNIX.
95*0Sstevel@tonic-gate
96*0Sstevel@tonic-gate=cut
97*0Sstevel@tonic-gate
98*0Sstevel@tonic-gatesub curdir () { '.' }
99*0Sstevel@tonic-gate
100*0Sstevel@tonic-gate=item devnull
101*0Sstevel@tonic-gate
102*0Sstevel@tonic-gateReturns a string representation of the null device. "/dev/null" on UNIX.
103*0Sstevel@tonic-gate
104*0Sstevel@tonic-gate=cut
105*0Sstevel@tonic-gate
106*0Sstevel@tonic-gatesub devnull () { '/dev/null' }
107*0Sstevel@tonic-gate
108*0Sstevel@tonic-gate=item rootdir
109*0Sstevel@tonic-gate
110*0Sstevel@tonic-gateReturns a string representation of the root directory.  "/" on UNIX.
111*0Sstevel@tonic-gate
112*0Sstevel@tonic-gate=cut
113*0Sstevel@tonic-gate
114*0Sstevel@tonic-gatesub rootdir () { '/' }
115*0Sstevel@tonic-gate
116*0Sstevel@tonic-gate=item tmpdir
117*0Sstevel@tonic-gate
118*0Sstevel@tonic-gateReturns a string representation of the first writable directory from
119*0Sstevel@tonic-gatethe following list or the current directory if none from the list are
120*0Sstevel@tonic-gatewritable:
121*0Sstevel@tonic-gate
122*0Sstevel@tonic-gate    $ENV{TMPDIR}
123*0Sstevel@tonic-gate    /tmp
124*0Sstevel@tonic-gate
125*0Sstevel@tonic-gateSince perl 5.8.0, if running under taint mode, and if $ENV{TMPDIR}
126*0Sstevel@tonic-gateis tainted, it is not used.
127*0Sstevel@tonic-gate
128*0Sstevel@tonic-gate=cut
129*0Sstevel@tonic-gate
130*0Sstevel@tonic-gatemy $tmpdir;
131*0Sstevel@tonic-gatesub _tmpdir {
132*0Sstevel@tonic-gate    return $tmpdir if defined $tmpdir;
133*0Sstevel@tonic-gate    my $self = shift;
134*0Sstevel@tonic-gate    my @dirlist = @_;
135*0Sstevel@tonic-gate    {
136*0Sstevel@tonic-gate	no strict 'refs';
137*0Sstevel@tonic-gate	if (${"\cTAINT"}) { # Check for taint mode on perl >= 5.8.0
138*0Sstevel@tonic-gate            require Scalar::Util;
139*0Sstevel@tonic-gate	    @dirlist = grep { ! Scalar::Util::tainted($_) } @dirlist;
140*0Sstevel@tonic-gate	}
141*0Sstevel@tonic-gate    }
142*0Sstevel@tonic-gate    foreach (@dirlist) {
143*0Sstevel@tonic-gate	next unless defined && -d && -w _;
144*0Sstevel@tonic-gate	$tmpdir = $_;
145*0Sstevel@tonic-gate	last;
146*0Sstevel@tonic-gate    }
147*0Sstevel@tonic-gate    $tmpdir = $self->curdir unless defined $tmpdir;
148*0Sstevel@tonic-gate    $tmpdir = defined $tmpdir && $self->canonpath($tmpdir);
149*0Sstevel@tonic-gate    return $tmpdir;
150*0Sstevel@tonic-gate}
151*0Sstevel@tonic-gate
152*0Sstevel@tonic-gatesub tmpdir {
153*0Sstevel@tonic-gate    return $tmpdir if defined $tmpdir;
154*0Sstevel@tonic-gate    my $self = shift;
155*0Sstevel@tonic-gate    $tmpdir = $self->_tmpdir( $ENV{TMPDIR}, "/tmp" );
156*0Sstevel@tonic-gate}
157*0Sstevel@tonic-gate
158*0Sstevel@tonic-gate=item updir
159*0Sstevel@tonic-gate
160*0Sstevel@tonic-gateReturns a string representation of the parent directory.  ".." on UNIX.
161*0Sstevel@tonic-gate
162*0Sstevel@tonic-gate=cut
163*0Sstevel@tonic-gate
164*0Sstevel@tonic-gatesub updir () { '..' }
165*0Sstevel@tonic-gate
166*0Sstevel@tonic-gate=item no_upwards
167*0Sstevel@tonic-gate
168*0Sstevel@tonic-gateGiven a list of file names, strip out those that refer to a parent
169*0Sstevel@tonic-gatedirectory. (Does not strip symlinks, only '.', '..', and equivalents.)
170*0Sstevel@tonic-gate
171*0Sstevel@tonic-gate=cut
172*0Sstevel@tonic-gate
173*0Sstevel@tonic-gatesub no_upwards {
174*0Sstevel@tonic-gate    my $self = shift;
175*0Sstevel@tonic-gate    return grep(!/^\.{1,2}\Z(?!\n)/s, @_);
176*0Sstevel@tonic-gate}
177*0Sstevel@tonic-gate
178*0Sstevel@tonic-gate=item case_tolerant
179*0Sstevel@tonic-gate
180*0Sstevel@tonic-gateReturns a true or false value indicating, respectively, that alphabetic
181*0Sstevel@tonic-gateis not or is significant when comparing file specifications.
182*0Sstevel@tonic-gate
183*0Sstevel@tonic-gate=cut
184*0Sstevel@tonic-gate
185*0Sstevel@tonic-gatesub case_tolerant () { 0 }
186*0Sstevel@tonic-gate
187*0Sstevel@tonic-gate=item file_name_is_absolute
188*0Sstevel@tonic-gate
189*0Sstevel@tonic-gateTakes as argument a path and returns true if it is an absolute path.
190*0Sstevel@tonic-gate
191*0Sstevel@tonic-gateThis does not consult the local filesystem on Unix, Win32, OS/2 or Mac
192*0Sstevel@tonic-gateOS (Classic).  It does consult the working environment for VMS (see
193*0Sstevel@tonic-gateL<File::Spec::VMS/file_name_is_absolute>).
194*0Sstevel@tonic-gate
195*0Sstevel@tonic-gate=cut
196*0Sstevel@tonic-gate
197*0Sstevel@tonic-gatesub file_name_is_absolute {
198*0Sstevel@tonic-gate    my ($self,$file) = @_;
199*0Sstevel@tonic-gate    return scalar($file =~ m:^/:s);
200*0Sstevel@tonic-gate}
201*0Sstevel@tonic-gate
202*0Sstevel@tonic-gate=item path
203*0Sstevel@tonic-gate
204*0Sstevel@tonic-gateTakes no argument, returns the environment variable PATH as an array.
205*0Sstevel@tonic-gate
206*0Sstevel@tonic-gate=cut
207*0Sstevel@tonic-gate
208*0Sstevel@tonic-gatesub path {
209*0Sstevel@tonic-gate    return () unless exists $ENV{PATH};
210*0Sstevel@tonic-gate    my @path = split(':', $ENV{PATH});
211*0Sstevel@tonic-gate    foreach (@path) { $_ = '.' if $_ eq '' }
212*0Sstevel@tonic-gate    return @path;
213*0Sstevel@tonic-gate}
214*0Sstevel@tonic-gate
215*0Sstevel@tonic-gate=item join
216*0Sstevel@tonic-gate
217*0Sstevel@tonic-gatejoin is the same as catfile.
218*0Sstevel@tonic-gate
219*0Sstevel@tonic-gate=cut
220*0Sstevel@tonic-gate
221*0Sstevel@tonic-gatesub join {
222*0Sstevel@tonic-gate    my $self = shift;
223*0Sstevel@tonic-gate    return $self->catfile(@_);
224*0Sstevel@tonic-gate}
225*0Sstevel@tonic-gate
226*0Sstevel@tonic-gate=item splitpath
227*0Sstevel@tonic-gate
228*0Sstevel@tonic-gate    ($volume,$directories,$file) = File::Spec->splitpath( $path );
229*0Sstevel@tonic-gate    ($volume,$directories,$file) = File::Spec->splitpath( $path, $no_file );
230*0Sstevel@tonic-gate
231*0Sstevel@tonic-gateSplits a path into volume, directory, and filename portions. On systems
232*0Sstevel@tonic-gatewith no concept of volume, returns '' for volume.
233*0Sstevel@tonic-gate
234*0Sstevel@tonic-gateFor systems with no syntax differentiating filenames from directories,
235*0Sstevel@tonic-gateassumes that the last file is a path unless $no_file is true or a
236*0Sstevel@tonic-gatetrailing separator or /. or /.. is present. On Unix this means that $no_file
237*0Sstevel@tonic-gatetrue makes this return ( '', $path, '' ).
238*0Sstevel@tonic-gate
239*0Sstevel@tonic-gateThe directory portion may or may not be returned with a trailing '/'.
240*0Sstevel@tonic-gate
241*0Sstevel@tonic-gateThe results can be passed to L</catpath()> to get back a path equivalent to
242*0Sstevel@tonic-gate(usually identical to) the original path.
243*0Sstevel@tonic-gate
244*0Sstevel@tonic-gate=cut
245*0Sstevel@tonic-gate
246*0Sstevel@tonic-gatesub splitpath {
247*0Sstevel@tonic-gate    my ($self,$path, $nofile) = @_;
248*0Sstevel@tonic-gate
249*0Sstevel@tonic-gate    my ($volume,$directory,$file) = ('','','');
250*0Sstevel@tonic-gate
251*0Sstevel@tonic-gate    if ( $nofile ) {
252*0Sstevel@tonic-gate        $directory = $path;
253*0Sstevel@tonic-gate    }
254*0Sstevel@tonic-gate    else {
255*0Sstevel@tonic-gate        $path =~ m|^ ( (?: .* / (?: \.\.?\Z(?!\n) )? )? ) ([^/]*) |xs;
256*0Sstevel@tonic-gate        $directory = $1;
257*0Sstevel@tonic-gate        $file      = $2;
258*0Sstevel@tonic-gate    }
259*0Sstevel@tonic-gate
260*0Sstevel@tonic-gate    return ($volume,$directory,$file);
261*0Sstevel@tonic-gate}
262*0Sstevel@tonic-gate
263*0Sstevel@tonic-gate
264*0Sstevel@tonic-gate=item splitdir
265*0Sstevel@tonic-gate
266*0Sstevel@tonic-gateThe opposite of L</catdir()>.
267*0Sstevel@tonic-gate
268*0Sstevel@tonic-gate    @dirs = File::Spec->splitdir( $directories );
269*0Sstevel@tonic-gate
270*0Sstevel@tonic-gate$directories must be only the directory portion of the path on systems
271*0Sstevel@tonic-gatethat have the concept of a volume or that have path syntax that differentiates
272*0Sstevel@tonic-gatefiles from directories.
273*0Sstevel@tonic-gate
274*0Sstevel@tonic-gateUnlike just splitting the directories on the separator, empty
275*0Sstevel@tonic-gatedirectory names (C<''>) can be returned, because these are significant
276*0Sstevel@tonic-gateon some OSs.
277*0Sstevel@tonic-gate
278*0Sstevel@tonic-gateOn Unix,
279*0Sstevel@tonic-gate
280*0Sstevel@tonic-gate    File::Spec->splitdir( "/a/b//c/" );
281*0Sstevel@tonic-gate
282*0Sstevel@tonic-gateYields:
283*0Sstevel@tonic-gate
284*0Sstevel@tonic-gate    ( '', 'a', 'b', '', 'c', '' )
285*0Sstevel@tonic-gate
286*0Sstevel@tonic-gate=cut
287*0Sstevel@tonic-gate
288*0Sstevel@tonic-gatesub splitdir {
289*0Sstevel@tonic-gate    return split m|/|, $_[1], -1;  # Preserve trailing fields
290*0Sstevel@tonic-gate}
291*0Sstevel@tonic-gate
292*0Sstevel@tonic-gate
293*0Sstevel@tonic-gate=item catpath()
294*0Sstevel@tonic-gate
295*0Sstevel@tonic-gateTakes volume, directory and file portions and returns an entire path. Under
296*0Sstevel@tonic-gateUnix, $volume is ignored, and directory and file are concatenated.  A '/' is
297*0Sstevel@tonic-gateinserted if needed (though if the directory portion doesn't start with
298*0Sstevel@tonic-gate'/' it is not added).  On other OSs, $volume is significant.
299*0Sstevel@tonic-gate
300*0Sstevel@tonic-gate=cut
301*0Sstevel@tonic-gate
302*0Sstevel@tonic-gatesub catpath {
303*0Sstevel@tonic-gate    my ($self,$volume,$directory,$file) = @_;
304*0Sstevel@tonic-gate
305*0Sstevel@tonic-gate    if ( $directory ne ''                &&
306*0Sstevel@tonic-gate         $file ne ''                     &&
307*0Sstevel@tonic-gate         substr( $directory, -1 ) ne '/' &&
308*0Sstevel@tonic-gate         substr( $file, 0, 1 ) ne '/'
309*0Sstevel@tonic-gate    ) {
310*0Sstevel@tonic-gate        $directory .= "/$file" ;
311*0Sstevel@tonic-gate    }
312*0Sstevel@tonic-gate    else {
313*0Sstevel@tonic-gate        $directory .= $file ;
314*0Sstevel@tonic-gate    }
315*0Sstevel@tonic-gate
316*0Sstevel@tonic-gate    return $directory ;
317*0Sstevel@tonic-gate}
318*0Sstevel@tonic-gate
319*0Sstevel@tonic-gate=item abs2rel
320*0Sstevel@tonic-gate
321*0Sstevel@tonic-gateTakes a destination path and an optional base path returns a relative path
322*0Sstevel@tonic-gatefrom the base path to the destination path:
323*0Sstevel@tonic-gate
324*0Sstevel@tonic-gate    $rel_path = File::Spec->abs2rel( $path ) ;
325*0Sstevel@tonic-gate    $rel_path = File::Spec->abs2rel( $path, $base ) ;
326*0Sstevel@tonic-gate
327*0Sstevel@tonic-gateIf $base is not present or '', then L<cwd()|Cwd> is used. If $base is
328*0Sstevel@tonic-gaterelative, then it is converted to absolute form using
329*0Sstevel@tonic-gateL</rel2abs()>. This means that it is taken to be relative to
330*0Sstevel@tonic-gateL<cwd()|Cwd>.
331*0Sstevel@tonic-gate
332*0Sstevel@tonic-gateOn systems that have a grammar that indicates filenames, this ignores the
333*0Sstevel@tonic-gate$base filename. Otherwise all path components are assumed to be
334*0Sstevel@tonic-gatedirectories.
335*0Sstevel@tonic-gate
336*0Sstevel@tonic-gateIf $path is relative, it is converted to absolute form using L</rel2abs()>.
337*0Sstevel@tonic-gateThis means that it is taken to be relative to L<cwd()|Cwd>.
338*0Sstevel@tonic-gate
339*0Sstevel@tonic-gateNo checks against the filesystem are made.  On VMS, there is
340*0Sstevel@tonic-gateinteraction with the working environment, as logicals and
341*0Sstevel@tonic-gatemacros are expanded.
342*0Sstevel@tonic-gate
343*0Sstevel@tonic-gateBased on code written by Shigio Yamaguchi.
344*0Sstevel@tonic-gate
345*0Sstevel@tonic-gate=cut
346*0Sstevel@tonic-gate
347*0Sstevel@tonic-gatesub abs2rel {
348*0Sstevel@tonic-gate    my($self,$path,$base) = @_;
349*0Sstevel@tonic-gate
350*0Sstevel@tonic-gate    # Clean up $path
351*0Sstevel@tonic-gate    if ( ! $self->file_name_is_absolute( $path ) ) {
352*0Sstevel@tonic-gate        $path = $self->rel2abs( $path ) ;
353*0Sstevel@tonic-gate    }
354*0Sstevel@tonic-gate    else {
355*0Sstevel@tonic-gate        $path = $self->canonpath( $path ) ;
356*0Sstevel@tonic-gate    }
357*0Sstevel@tonic-gate
358*0Sstevel@tonic-gate    # Figure out the effective $base and clean it up.
359*0Sstevel@tonic-gate    if ( !defined( $base ) || $base eq '' ) {
360*0Sstevel@tonic-gate        $base = $self->_cwd();
361*0Sstevel@tonic-gate    }
362*0Sstevel@tonic-gate    elsif ( ! $self->file_name_is_absolute( $base ) ) {
363*0Sstevel@tonic-gate        $base = $self->rel2abs( $base ) ;
364*0Sstevel@tonic-gate    }
365*0Sstevel@tonic-gate    else {
366*0Sstevel@tonic-gate        $base = $self->canonpath( $base ) ;
367*0Sstevel@tonic-gate    }
368*0Sstevel@tonic-gate
369*0Sstevel@tonic-gate    # Now, remove all leading components that are the same
370*0Sstevel@tonic-gate    my @pathchunks = $self->splitdir( $path);
371*0Sstevel@tonic-gate    my @basechunks = $self->splitdir( $base);
372*0Sstevel@tonic-gate
373*0Sstevel@tonic-gate    while (@pathchunks && @basechunks && $pathchunks[0] eq $basechunks[0]) {
374*0Sstevel@tonic-gate        shift @pathchunks ;
375*0Sstevel@tonic-gate        shift @basechunks ;
376*0Sstevel@tonic-gate    }
377*0Sstevel@tonic-gate
378*0Sstevel@tonic-gate    $path = CORE::join( '/', @pathchunks );
379*0Sstevel@tonic-gate    $base = CORE::join( '/', @basechunks );
380*0Sstevel@tonic-gate
381*0Sstevel@tonic-gate    # $base now contains the directories the resulting relative path
382*0Sstevel@tonic-gate    # must ascend out of before it can descend to $path_directory.  So,
383*0Sstevel@tonic-gate    # replace all names with $parentDir
384*0Sstevel@tonic-gate    $base =~ s|[^/]+|..|g ;
385*0Sstevel@tonic-gate
386*0Sstevel@tonic-gate    # Glue the two together, using a separator if necessary, and preventing an
387*0Sstevel@tonic-gate    # empty result.
388*0Sstevel@tonic-gate    if ( $path ne '' && $base ne '' ) {
389*0Sstevel@tonic-gate        $path = "$base/$path" ;
390*0Sstevel@tonic-gate    } else {
391*0Sstevel@tonic-gate        $path = "$base$path" ;
392*0Sstevel@tonic-gate    }
393*0Sstevel@tonic-gate
394*0Sstevel@tonic-gate    return $self->canonpath( $path ) ;
395*0Sstevel@tonic-gate}
396*0Sstevel@tonic-gate
397*0Sstevel@tonic-gate=item rel2abs()
398*0Sstevel@tonic-gate
399*0Sstevel@tonic-gateConverts a relative path to an absolute path.
400*0Sstevel@tonic-gate
401*0Sstevel@tonic-gate    $abs_path = File::Spec->rel2abs( $path ) ;
402*0Sstevel@tonic-gate    $abs_path = File::Spec->rel2abs( $path, $base ) ;
403*0Sstevel@tonic-gate
404*0Sstevel@tonic-gateIf $base is not present or '', then L<cwd()|Cwd> is used. If $base is
405*0Sstevel@tonic-gaterelative, then it is converted to absolute form using
406*0Sstevel@tonic-gateL</rel2abs()>. This means that it is taken to be relative to
407*0Sstevel@tonic-gateL<cwd()|Cwd>.
408*0Sstevel@tonic-gate
409*0Sstevel@tonic-gateOn systems that have a grammar that indicates filenames, this ignores
410*0Sstevel@tonic-gatethe $base filename. Otherwise all path components are assumed to be
411*0Sstevel@tonic-gatedirectories.
412*0Sstevel@tonic-gate
413*0Sstevel@tonic-gateIf $path is absolute, it is cleaned up and returned using L</canonpath()>.
414*0Sstevel@tonic-gate
415*0Sstevel@tonic-gateNo checks against the filesystem are made.  On VMS, there is
416*0Sstevel@tonic-gateinteraction with the working environment, as logicals and
417*0Sstevel@tonic-gatemacros are expanded.
418*0Sstevel@tonic-gate
419*0Sstevel@tonic-gateBased on code written by Shigio Yamaguchi.
420*0Sstevel@tonic-gate
421*0Sstevel@tonic-gate=cut
422*0Sstevel@tonic-gate
423*0Sstevel@tonic-gatesub rel2abs {
424*0Sstevel@tonic-gate    my ($self,$path,$base ) = @_;
425*0Sstevel@tonic-gate
426*0Sstevel@tonic-gate    # Clean up $path
427*0Sstevel@tonic-gate    if ( ! $self->file_name_is_absolute( $path ) ) {
428*0Sstevel@tonic-gate        # Figure out the effective $base and clean it up.
429*0Sstevel@tonic-gate        if ( !defined( $base ) || $base eq '' ) {
430*0Sstevel@tonic-gate	    $base = $self->_cwd();
431*0Sstevel@tonic-gate        }
432*0Sstevel@tonic-gate        elsif ( ! $self->file_name_is_absolute( $base ) ) {
433*0Sstevel@tonic-gate            $base = $self->rel2abs( $base ) ;
434*0Sstevel@tonic-gate        }
435*0Sstevel@tonic-gate        else {
436*0Sstevel@tonic-gate            $base = $self->canonpath( $base ) ;
437*0Sstevel@tonic-gate        }
438*0Sstevel@tonic-gate
439*0Sstevel@tonic-gate        # Glom them together
440*0Sstevel@tonic-gate        $path = $self->catdir( $base, $path ) ;
441*0Sstevel@tonic-gate    }
442*0Sstevel@tonic-gate
443*0Sstevel@tonic-gate    return $self->canonpath( $path ) ;
444*0Sstevel@tonic-gate}
445*0Sstevel@tonic-gate
446*0Sstevel@tonic-gate=back
447*0Sstevel@tonic-gate
448*0Sstevel@tonic-gate=head1 SEE ALSO
449*0Sstevel@tonic-gate
450*0Sstevel@tonic-gateL<File::Spec>
451*0Sstevel@tonic-gate
452*0Sstevel@tonic-gate=cut
453*0Sstevel@tonic-gate
454*0Sstevel@tonic-gate# Internal routine to File::Spec, no point in making this public since
455*0Sstevel@tonic-gate# it is the standard Cwd interface.  Most of the platform-specific
456*0Sstevel@tonic-gate# File::Spec subclasses use this.
457*0Sstevel@tonic-gatesub _cwd {
458*0Sstevel@tonic-gate    require Cwd;
459*0Sstevel@tonic-gate    Cwd::cwd();
460*0Sstevel@tonic-gate}
461*0Sstevel@tonic-gate
462*0Sstevel@tonic-gate1;
463