Update ordinals and include changes from 0.9.8.
[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 $arg;
12
13 foreach $arg (@ARGV) {
14         foreach (glob $arg)
15                 {
16                 push @filelist, $_;
17                 }
18 }
19
20 $fnum = @filelist;
21
22 if ($fnum <= 1)
23         {
24         die "Need at least two filenames";
25         }
26
27 $dest = pop @filelist;
28         
29 if ($fnum > 2 && ! -d $dest)
30         {
31         die "Destination must be a directory";
32         }
33
34 foreach (@filelist)
35         {
36         if (-d $dest)
37                 {
38                 $dfile = $_;
39                 $dfile =~ s|^.*[/\\]([^/\\]*)$|$1|;
40                 $dfile = "$dest/$dfile";
41                 }
42         else
43                 {
44                 $dfile = $dest;
45                 }
46         sysopen(IN, $_, O_RDONLY|O_BINARY) || die "Can't Open $_";
47         sysopen(OUT, $dfile, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY)
48                                         || die "Can't Open $dfile";
49         while (sysread IN, $buf, 10240)
50                 {
51                 syswrite(OUT, $buf, length($buf));
52                 }
53         close(IN);
54         close(OUT);
55         print "Copying: $_ to $dfile\n";
56         }
57                 
58