1 package File::Spec::OS2;
4 use vars qw(@ISA $VERSION);
5 require File::Spec::Unix;
9 @ISA = qw(File::Spec::Unix);
19 sub file_name_is_absolute {
20 my ($self,$file) = @_;
21 return scalar($file =~ m{^([a-z]:)?[\\/]}is);
25 my $path = $ENV{PATH};
27 my @path = split(';',$path);
28 foreach (@path) { $_ = '.' if $_ eq '' }
36 Returns a string representation of the first existing directory
37 from the following list:
45 Since Perl 5.8.0, if running under taint mode, and if the environment
46 variables are tainted, they are not used.
52 return $tmpdir if defined $tmpdir;
54 $tmpdir = $self->_tmpdir( @ENV{qw(TMPDIR TEMP TMP)},
61 No physical check on the filesystem, but a logical cleanup of a
62 path. On UNIX eliminated successive slashes and successive "/.".
67 my ($self,$path) = @_;
68 $path =~ s/^([a-z]:)/\l$1/s;
70 $path =~ s|([^/])/+|$1/|g; # xx////xx -> xx/xx
71 $path =~ s|(/\.)+/|/|g; # xx/././xx -> xx/xx
72 $path =~ s|^(\./)+(?=[^/])||s; # ./xx -> xx
73 $path =~ s|/\Z(?!\n)||
74 unless $path =~ m#^([a-z]:)?/\Z(?!\n)#si;# xx/ -> xx
80 ($volume,$directories,$file) = File::Spec->splitpath( $path );
81 ($volume,$directories,$file) = File::Spec->splitpath( $path, $no_file );
83 Splits a path into volume, directory, and filename portions. Assumes that
84 the last file is a path unless the path ends in '/', '/.', '/..'
85 or $no_file is true. On Win32 this means that $no_file true makes this return
86 ( $volume, $path, '' ).
88 Separators accepted are \ and /.
90 Volumes can be drive letters or UNC sharenames (\\server\share).
92 The results can be passed to L</catpath> to get back a path equivalent to
93 (usually identical to) the original path.
98 my ($self,$path, $nofile) = @_;
99 my ($volume,$directory,$file) = ('','','');
102 m{^( (?:[a-zA-Z]:|(?:\\\\|//)[^\\/]+[\\/][^\\/]+)? )
110 m{^ ( (?: [a-zA-Z]: |
111 (?:\\\\|//)[^\\/]+[\\/][^\\/]+
114 ( (?:.*[\\\\/](?:\.\.?\Z(?!\n))?)? )
122 return ($volume,$directory,$file);
128 The opposite of L<catdir()|File::Spec/catdir()>.
130 @dirs = File::Spec->splitdir( $directories );
132 $directories must be only the directory portion of the path on systems
133 that have the concept of a volume or that have path syntax that differentiates
134 files from directories.
136 Unlike just splitting the directories on the separator, leading empty and
137 trailing directory entries can be returned, because these are significant
140 File::Spec->splitdir( "/a/b//c/" );
144 ( '', 'a', 'b', '', 'c', '' )
149 my ($self,$directories) = @_ ;
150 split m|[\\/]|, $directories, -1;
156 Takes volume, directory and file portions and returns an entire path. Under
157 Unix, $volume is ignored, and this is just like catfile(). On other OSs,
158 the $volume become significant.
163 my ($self,$volume,$directory,$file) = @_;
165 # If it's UNC, make sure the glue separator is there, reusing
166 # whatever separator is first in the $volume
168 if ( $volume =~ m@^([\\/])[\\/][^\\/]+[\\/][^\\/]+\Z(?!\n)@s &&
169 $directory =~ m@^[^\\/]@s
172 $volume .= $directory ;
174 # If the volume is not just A:, make sure the glue separator is
175 # there, reusing whatever separator is first in the $volume if possible.
176 if ( $volume !~ m@^[a-zA-Z]:\Z(?!\n)@s &&
177 $volume =~ m@[^\\/]\Z(?!\n)@ &&
180 $volume =~ m@([\\/])@ ;
181 my $sep = $1 ? $1 : '/' ;
192 my($self,$path,$base) = @_;
195 if ( ! $self->file_name_is_absolute( $path ) ) {
196 $path = $self->rel2abs( $path ) ;
198 $path = $self->canonpath( $path ) ;
201 # Figure out the effective $base and clean it up.
202 if ( !defined( $base ) || $base eq '' ) {
204 $base = Cwd::sys_cwd() ;
205 } elsif ( ! $self->file_name_is_absolute( $base ) ) {
206 $base = $self->rel2abs( $base ) ;
208 $base = $self->canonpath( $base ) ;
212 my ( undef, $path_directories, $path_file ) =
213 $self->splitpath( $path, 1 ) ;
215 my $base_directories = ($self->splitpath( $base, 1 ))[1] ;
217 # Now, remove all leading components that are the same
218 my @pathchunks = $self->splitdir( $path_directories );
219 my @basechunks = $self->splitdir( $base_directories );
221 while ( @pathchunks &&
223 lc( $pathchunks[0] ) eq lc( $basechunks[0] )
229 # No need to catdir, we know these are well formed.
230 $path_directories = CORE::join( '/', @pathchunks );
231 $base_directories = CORE::join( '/', @basechunks );
233 # $base_directories now contains the directories the resulting relative
234 # path must ascend out of before it can descend to $path_directory. So,
235 # replace all names with $parentDir
237 #FA Need to replace between backslashes...
238 $base_directories =~ s|[^\\/]+|..|g ;
240 # Glue the two together, using a separator if necessary, and preventing an
243 #FA Must check that new directories are not empty.
244 if ( $path_directories ne '' && $base_directories ne '' ) {
245 $path_directories = "$base_directories/$path_directories" ;
247 $path_directories = "$base_directories$path_directories" ;
250 return $self->canonpath(
251 $self->catpath( "", $path_directories, $path_file )
257 my ($self,$path,$base ) = @_;
259 if ( ! $self->file_name_is_absolute( $path ) ) {
261 if ( !defined( $base ) || $base eq '' ) {
263 $base = Cwd::sys_cwd() ;
265 elsif ( ! $self->file_name_is_absolute( $base ) ) {
266 $base = $self->rel2abs( $base ) ;
269 $base = $self->canonpath( $base ) ;
272 my ( $path_directories, $path_file ) =
273 ($self->splitpath( $path, 1 ))[1,2] ;
275 my ( $base_volume, $base_directories ) =
276 $self->splitpath( $base, 1 ) ;
278 $path = $self->catpath(
280 $self->catdir( $base_directories, $path_directories ),
285 return $self->canonpath( $path ) ;
293 File::Spec::OS2 - methods for OS/2 file specs
297 require File::Spec::OS2; # Done internally by File::Spec if needed
301 See L<File::Spec> and L<File::Spec::Unix>. This package overrides the
302 implementation of these methods, not the semantics.