summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPerl 5 Porters <perl5-porters@africa.nicoh.com>1996-12-23 12:58:58 +1200
committerChip Salzenberg <chip@atlantic.net>1996-12-23 12:58:58 +1200
commit71be2cbc73608e37e1a2ab7e459a02111137d1b0 (patch)
tree86679f00907a9abdfd1ff5104cec60d9a9fb0ef9 /lib
parentb133f4ec823b00faf9bd083e0eb8e7a53ba7bfca (diff)
downloadperl-71be2cbc73608e37e1a2ab7e459a02111137d1b0.tar.gz
[inseparable changes from patch from perl5.003_13 to perl5.003_14]
CORE LANGUAGE CHANGES Subject: Eliminate support for {if,unless,while,until} BLOCK BLOCK From: Chip Salzenberg <chip@atlantic.net> Files: perly.c perly.c.diff perly.y toke.c Subject: Taint $x after $x =~ s/pat/xyz/ if pat or xyz is tainted by locale From: Chip Salzenberg <chip@atlantic.net> Files: cop.h mg.c pp_ctl.c pp_hot.c Subject: Complete support for modifying undefined array members in foreach From: Chip Salzenberg <chip@atlantic.net> Files: global.sym mg.c perl.h pp.c pp_hot.c proto.h sv.c DOCUMENTATION Subject: Update pod/Makefile; s/perli18n/perllocale/ From: Chip Salzenberg <chip@atlantic.net> Files: ext/POSIX/POSIX.pod lib/I18N/Collate.pm pod/Makefile pod/perl.pod pod/perlmod.pod pod/perlnews.pod pod/roffitall OTHER CORE CHANGES Subject: Bug in debugger with import manipulations Date: Mon, 23 Dec 1996 05:37:48 -0500 (EST) From: Ilya Zakharevich <ilya@math.ohio-state.edu> Files: pp_hot.c Finally I traced why MakeMaker runs wrongly under debugger: debugger function calling sequence was assuming that GvCV(CvGV(cv)) == cv for non-anonymous subs (ne END). MakeMaker managed to break it by *A::B = \&C::D; eval 'sub C::D {new one}'; After this CvGV(\&A::B) is *C::D, but &{*C::D} is the "new one". Patch follows (note that in this case we do not sacrifice having a subroutine name in debugger output ;-). Enjoy, p5p-msgid: <199612231037.FAA08617@monk.mps.ohio-state.edu> Subject: Import and dynamic methods Date: Mon, 23 Dec 1996 01:45:37 -0500 (EST) From: Ilya Zakharevich <ilya@math.ohio-state.edu> Files: gv.c hv.c sv.c Here is the patch which corrects bad things which happens when you import subroutines and otherwise manipulate the symbol tree. I put forward the only chunk which may be controversal, since it may have a minor performance penalty. It is independent of the others, so it can be freely deleted. The manipulations which correctly propagate to method calls: a) Pruning globs: delete $B::{method} b) Undefing subroutines: undef &B::method; c) Importing: *B::method = \&mymethod; Enjoy, p5p-msgid: <199612230645.BAA08378@monk.mps.ohio-state.edu> Subject: sv_gets patch Date: Sun, 22 Dec 1996 03:24:04 -0500 (EST) From: Ilya Zakharevich <ilya@math.ohio-state.edu> Files: pp_hot.c I sent this patch before as a part of pos $str = $str = /failing/g patch. Now I separate it in the case it was tainted by environment: Synopsis: $a = <FH>; does not work as expected if $a is magic (say, tied). Enjoy, p5p-msgid: <199612220824.DAA07235@monk.mps.ohio-state.edu> Subject: pos $str patch Date: Sun, 22 Dec 1996 03:31:21 -0500 (EST) From: Ilya Zakharevich <ilya@math.ohio-state.edu> Files: mg.c pp_hot.c t/op/pat.t This patch was (mostly) posted already. It fixes the bug: pos $str is reset to undef if $str =~ /failing/g fails. Additionally, if fixes the hidded bit (=MGf_MINMATCH) surviving setting pos $str = ... Enjoy, p5p-msgid: <199612220831.DAA07247@monk.mps.ohio-state.edu> PORTABILITY Subject: Fix bugs in bincompat3 usage From: Chip Salzenberg <chip@atlantic.net> Files: perl.h perl_exp.SH Subject: VMS patches to 5.003_13 Date: Mon, 23 Dec 1996 01:26:47 -0500 (EST) From: Charles Bailey <bailey@HMIVAX.HUMGEN.UPENN.EDU> Files: deb.c ext/POSIX/POSIX.xs gv.c lib/File/Copy.pm mg.c perl.c perl.h proto.h sv.c t/lib/filecopy.t taint.c toke.c util.c vms/Makefile vms/config.vms vms/descrip.mms vms/gen_shrfls.pl vms/genconfig.pl vms/genopt.com vms/perly_c.vms vms/perly_h.vms vms/test.com vms/vms.c vms/vms_yfix.pl private-msgid: <01IDBYYFYPIS002ASE@hmivax.humgen.upenn.edu> UTILITIES, LIBRARY, AND EXTENSIONS Subject: Remove libnet From: Chip Salzenberg <chip@atlantic.net> Files: MANIFEST pod/perlmod.pod Subject: Update IO->VERSION() to 1.1201 for CPAN's sake From: Chip Salzenberg <chip@atlantic.net> Files: ext/IO/lib/IO/Handle.pm lib/IO/Handle.pm Subject: Remodel File::Copy. From: Chip Salzenberg <chip@atlantic.net> Files: lib/File/Copy.pm
Diffstat (limited to 'lib')
-rw-r--r--lib/File/Copy.pm193
-rw-r--r--lib/I18N/Collate.pm2
2 files changed, 125 insertions, 70 deletions
diff --git a/lib/File/Copy.pm b/lib/File/Copy.pm
index 6afbd393b3..70c5eb81e6 100644
--- a/lib/File/Copy.pm
+++ b/lib/File/Copy.pm
@@ -2,64 +2,93 @@
# source code has been placed in the public domain by the author.
# Please be kind and preserve the documentation.
#
+# Additions copyright 1996 by Charles Bailey. Permission is granted
+# to distribute the revised code under the same terms as Perl itself.
package File::Copy;
-use Exporter;
+use strict;
use Carp;
use UNIVERSAL qw(isa);
-use vars qw( @ISA @EXPORT @EXPORT_OK $VERSION $Too_Big);
-use strict;
+use vars qw(@ISA @EXPORT @EXPORT_OK $VERSION $Too_Big
+ &copy &syscopy &cp &mv);
+
+# Note that this module implements only *part* of the API defined by
+# the File/Copy.pm module of the File-Tools-2.0 package. However, that
+# package has not yet been updated to work with Perl 5.004, and so it
+# would be a Bad Thing for the CPAN module to grab it and replace this
+# module. Therefore, we set this module's version higher than 2.0.
+$VERSION = '2.01';
-@ISA=qw(Exporter);
-@EXPORT=qw(copy move);
-@EXPORT_OK=qw(cp mv);
+require Exporter;
+@ISA = qw(Exporter);
+@EXPORT = qw(copy move);
+@EXPORT_OK = qw(cp mv);
-$VERSION = '1.6';
$Too_Big = 1024 * 1024 * 2;
-sub VERSION {
- # Version of File::Copy
- return $VERSION;
+sub _catname { # Will be replaced by File::Spec when it arrives
+ my($from, $to) = @_;
+ if (not defined &basename) {
+ require File::Basename;
+ import File::Basename 'basename';
+ }
+ if ($^O eq 'VMS') { $to = VMS::Filespec::vmspath($to) . basename($from); }
+ elsif ($^O eq 'MacOS') { $to .= ':' . basename($from); }
+ elsif ($to =~ m|\\|) { $to .= '\\' . basename($from); }
+ else { $to .= '/' . basename($from); }
}
sub copy {
- croak("Usage: copy( file1, file2 [, buffersize]) ")
+ croak("Usage: copy(FROM, TO [, BUFFERSIZE]) ")
unless(@_ == 2 || @_ == 3);
- if (defined &File::Copy::syscopy &&
- \&File::Copy::syscopy != \&File::Copy::copy &&
- ref(\$_[1]) ne 'GLOB' &&
- !(defined ref $_[1] and isa($_[1], 'GLOB')))
- { return File::Copy::syscopy($_[0],$_[1]) }
-
my $from = shift;
my $to = shift;
- my $closefrom=0;
- my $closeto=0;
+
+ my $from_a_handle = (ref($from)
+ ? (ref($from) eq 'GLOB'
+ || isa($from, 'GLOB') || isa($from, 'IO::Handle'))
+ : (ref(\$from) eq 'GLOB'));
+ my $to_a_handle = (ref($to)
+ ? (ref($to) eq 'GLOB'
+ || isa($to, 'GLOB') || isa($to, 'IO::Handle'))
+ : (ref(\$to) eq 'GLOB'));
+
+ if (!$from_a_handle && !$to_a_handle && -d $to && ! -d $from) {
+ $to = _catname($from, $to);
+ }
+
+ if (defined &syscopy && \&syscopy != \&copy
+ && $from_a_handle
+ && ($to_a_handle || $^O eq 'os2'))
+ {
+ return syscopy($from, $to);
+ }
+
+ my $closefrom = 0;
+ my $closeto = 0;
my ($size, $status, $r, $buf);
local(*FROM, *TO);
local($\) = '';
- if (ref($from) && (isa($from,'GLOB') || isa($from,'IO::Handle'))) {
- *FROM = *$from;
- } elsif (ref(\$from) eq 'GLOB') {
- *FROM = $from;
+ if ($from_a_handle) {
+ *FROM = *$from{FILEHANDLE};
} else {
- open(FROM,"<$from") or goto fail_open1;
- binmode FROM;
+ $from = "./$from" if $from =~ /^\s/;
+ open(FROM, "< $from\0") or goto fail_open1;
+ binmode FROM or die "($!,$^E)";
$closefrom = 1;
- }
-
- if (ref($to) && (isa($to,'GLOB') || isa($to,'IO::Handle'))) {
- *TO = *$to;
- } elsif (ref(\$to) eq 'GLOB') {
- *TO = $to;
- } else {
- open(TO,">$to") or goto fail_open2;
- binmode TO;
- $closeto=1;
- }
+ }
+
+ if ($to_a_handle) {
+ *TO = *$to{FILEHANDLE};
+ } else {
+ $to = "./$to" if $to =~ /^\s/;
+ open(TO,"> $to\0") or goto fail_open2;
+ binmode TO or die "($!,$^E)";
+ $closeto = 1;
+ }
if (@_) {
$size = shift(@_) + 0;
@@ -70,15 +99,21 @@ sub copy {
$size = $Too_Big if ($size > $Too_Big);
}
- $buf = '';
- while(defined($r = read(FROM,$buf,$size)) && $r > 0) {
- if (syswrite (TO,$buf,$r) != $r) {
- goto fail_inner;
+ $! = 0;
+ for (;;) {
+ my ($r, $w, $t);
+ defined($r = sysread(FROM, $buf, $size))
+ or goto fail_inner;
+ last unless $r;
+ for ($w = 0; $w < $r; $w += $t) {
+ $t = syswrite(TO, $buf, $r - $w, $w)
+ or goto fail_inner;
}
}
- goto fail_inner unless defined($r);
+
close(TO) || goto fail_open2 if $closeto;
close(FROM) || goto fail_open1 if $closefrom;
+
# Use this idiom to avoid uninitialized value warning.
return 1;
@@ -102,26 +137,37 @@ sub copy {
}
sub move {
- my($from,$to) = @_;
- my($copied,$tosz1,$tomt1,$tosz2,$tomt2,$sts,$ossts);
+ my($from,$to) = @_;
+ my($copied,$fromsz,$tosz1,$tomt1,$tosz2,$tomt2,$sts,$ossts);
- return 1 if rename $from, $to;
+ if (-d $to && ! -d $from) {
+ $to = _catname($from, $to);
+ }
+
+ ($tosz1,$tomt1) = (stat($to))[7,9];
+ $fromsz = -s $from;
+ return 1 if rename $from, $to;
+
+ ($sts,$ossts) = ($! + 0, $^E + 0);
+ # Did rename return an error even though it succeeded, because $to
+ # is on a remote NFS file system, and NFS lost the server's ack?
+ return 1 if defined($fromsz) && !-e $from && # $from disappeared
+ (($tosz2,$tomt2) = (stat($to))[7,9]) && # $to's there
+ ($tosz1 != $tosz2 or $tomt1 != $tomt2) && # and changed
+ $tosz2 == $fromsz; # it's all there
- ($tosz1,$tomt1) = (stat($to))[7,9];
- return 1 if ($copied = copy($from,$to)) && unlink($from);
+ ($tosz1,$tomt1) = (stat($to))[7,9]; # just in case rename did something
+ return 1 if ($copied = copy($from,$to)) && unlink($from);
- ($sts,$ossts) = ($! + 0, $^E + 0);
- ($tosz2,$tomt2) = ((stat($to))[7,9],0,0) if defined $tomt1;
- unlink($to) if !defined($tomt1) || $tomt1 != $tomt2 || $tosz1 != $tosz2;
- ($!,$^E) = ($sts,$ossts);
- return 0;
+ ($tosz2,$tomt2) = ((stat($to))[7,9],0,0) if defined $tomt1;
+ unlink($to) if !defined($tomt1) or $tomt1 != $tomt2 or $tosz1 != $tosz2;
+ ($!,$^E) = ($sts,$ossts);
+ return 0;
}
-{
- local($^W) = 0; # Hush up used-once warning
- *cp = \&copy;
- *mv = \&move;
-}
+*cp = \&copy;
+*mv = \&move;
+
# &syscopy is an XSUB under OS/2
*syscopy = ($^O eq 'VMS' ? \&rmscopy : \&copy) unless defined &syscopy;
@@ -163,10 +209,14 @@ argument may be a string, a FileHandle reference or a FileHandle
glob. Obviously, if the first argument is a filehandle of some
sort, it will be read from, and if it is a file I<name> it will
be opened for reading. Likewise, the second argument will be
-written to (and created if need be). Note that passing in
+written to (and created if need be). If the second argument is
+a file name and specifies an existing directory, and the first
+argument does not specify
+
+B<Note that passing in
files as handles instead of names may lead to loss of information
on some operating systems; it is recommended that you use file
-names whenever possible.
+names whenever possible.>
An optional third parameter can be used to specify the buffer
size used for copying. This is the number of bytes from the
@@ -181,10 +231,14 @@ You may use the syntax C<use File::Copy "cp"> to get at the
=item *
The C<move> function also takes two parameters: the current name
-and the intended name of the file to be moved. If possible, it
-will simply rename the file. Otherwise, it copies the file to
-the new location and deletes the original. If an error occurs during
-this copy-and-delete process, you may be left with a (possibly partial)
+and the intended name of the file to be moved. If the destination
+already exists and is a directory, and the source is not a
+directory, then the source file will be renamed into the directory
+specified by the destination.
+
+If possible, move() will simply rename the file. Otherwise, it copies
+the file to the new location and deletes the original. If an error occurs
+during this copy-and-delete process, you may be left with a (possibly partial)
copy of the file under the destination name.
You may use the "mv" alias for this function in the same way that
@@ -202,25 +256,26 @@ XSUB directly.
=head2 Special behavior if C<syscopy> is defined (VMS and OS/2)
-If the second argument to C<copy> is not a file handle for an
-already opened file, then C<copy> will perform a "system copy" of
+If both arguments to C<copy> are not file handles,
+then C<copy> will perform a "system copy" of
the input file to a new output file, in order to preserve file
attributes, indexed file structure, I<etc.> The buffer size
-parameter is ignored. If the second argument to C<copy> is a
-Perl handle to an opened file, then data is copied using Perl
+parameter is ignored. If either argument to C<copy> is a
+handle to an opened file, then data is copied using Perl
operators, and no effort is made to preserve file attributes
or record structure.
The system copy routine may also be called directly under VMS and OS/2
as C<File::Copy::syscopy> (or under VMS as C<File::Copy::rmscopy>, which
-is just an alias for this routine).
+is the routine that does the actual work for syscopy).
=over 4
=item rmscopy($from,$to[,$date_flag])
-The first and second arguments may be strings, typeglobs, or
-typeglob references; they are used in all cases to obtain the
+The first and second arguments may be strings, typeglobs, typeglob
+references, or objects inheriting from IO::Handle;
+they are used in all cases to obtain the
I<filespec> of the input and output files, respectively. The
name and type of the input file are used as defaults for the
output file, if necessary.
diff --git a/lib/I18N/Collate.pm b/lib/I18N/Collate.pm
index 18c46da835..343cb02205 100644
--- a/lib/I18N/Collate.pm
+++ b/lib/I18N/Collate.pm
@@ -125,7 +125,7 @@ sub new {
migrate the old applications away from it) because its functionality was
integrated into the Perl core language in the release 5.003_06.
- See pod/perli18n.pod for further information.
+ See pod/perllocale.pod for further information.
***
___EOD___