]> git.ipfire.org Git - thirdparty/openssl.git/blob - util/copy.pl
Prepare for 1.0.2u-dev
[thirdparty/openssl.git] / util / copy.pl
1 #!/usr/local/bin/perl
2
3 use Fcntl;
4
5
6 # copy.pl
7
8 # Perl script 'copy' comment. On Windows the built in "copy" command also
9 # copies timestamps: this messes up Makefile dependencies.
10
11 my $stripcr = 0;
12
13 my $arg;
14
15 foreach $arg (@ARGV) {
16 if ($arg eq "-stripcr")
17 {
18 $stripcr = 1;
19 next;
20 }
21 $arg =~ s|\\|/|g; # compensate for bug/feature in cygwin glob...
22 $arg = qq("$arg") if ($arg =~ /\s/); # compensate for bug in 5.10...
23 foreach (glob $arg)
24 {
25 push @filelist, $_;
26 }
27 }
28
29 $fnum = @filelist;
30
31 if ($fnum <= 1)
32 {
33 die "Need at least two filenames";
34 }
35
36 $dest = pop @filelist;
37
38 if ($fnum > 2 && ! -d $dest)
39 {
40 die "Destination must be a directory";
41 }
42
43 foreach (@filelist)
44 {
45 if (-d $dest)
46 {
47 $dfile = $_;
48 $dfile =~ s|^.*[/\\]([^/\\]*)$|$1|;
49 $dfile = "$dest/$dfile";
50 }
51 else
52 {
53 $dfile = $dest;
54 }
55 sysopen(IN, $_, O_RDONLY|O_BINARY) || die "Can't Open $_";
56 sysopen(OUT, $dfile, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY)
57 || die "Can't Open $dfile";
58 while (sysread IN, $buf, 10240)
59 {
60 if ($stripcr)
61 {
62 $buf =~ tr/\015//d;
63 }
64 syswrite(OUT, $buf, length($buf));
65 }
66 close(IN);
67 close(OUT);
68 print "Copying: $_ to $dfile\n";
69 }
70
71