]>
Commit | Line | Data |
---|---|---|
e0a65194 | 1 | #! /usr/bin/env perl |
83cf7abf | 2 | # Copyright 2005-2018 The OpenSSL Project Authors. All Rights Reserved. |
e0a65194 | 3 | # |
9059ab42 | 4 | # Licensed under the Apache License 2.0 (the "License"). You may not use |
e0a65194 RS |
5 | # this file except in compliance with the License. You can obtain a copy |
6 | # in the file LICENSE in the source distribution or at | |
7 | # https://www.openssl.org/source/license.html | |
8 | ||
fbf002bb DSH |
9 | |
10 | use Fcntl; | |
11 | ||
12 | ||
13 | # copy.pl | |
14 | ||
15 | # Perl script 'copy' comment. On Windows the built in "copy" command also | |
16 | # copies timestamps: this messes up Makefile dependencies. | |
17 | ||
7dbbd4b3 DSH |
18 | my $stripcr = 0; |
19 | ||
fbf002bb | 20 | my $arg; |
246bd8fd | 21 | my @excludes = (); |
fbf002bb DSH |
22 | |
23 | foreach $arg (@ARGV) { | |
7dbbd4b3 DSH |
24 | if ($arg eq "-stripcr") |
25 | { | |
26 | $stripcr = 1; | |
27 | next; | |
28 | } | |
246bd8fd RL |
29 | if ($arg =~ /^-exclude_re=(.*)$/) |
30 | { | |
31 | push @excludes, $1; | |
32 | next; | |
33 | } | |
68e57536 | 34 | $arg =~ s|\\|/|g; # compensate for bug/feature in cygwin glob... |
1097d2a3 | 35 | $arg = qq("$arg") if ($arg =~ /\s/); # compensate for bug in 5.10... |
246bd8fd | 36 | foreach my $f (glob $arg) |
fbf002bb | 37 | { |
246bd8fd | 38 | push @filelist, $f unless grep { $f =~ /$_/ } @excludes; |
fbf002bb DSH |
39 | } |
40 | } | |
41 | ||
42 | $fnum = @filelist; | |
43 | ||
44 | if ($fnum <= 1) | |
45 | { | |
46 | die "Need at least two filenames"; | |
47 | } | |
48 | ||
49 | $dest = pop @filelist; | |
609b0852 | 50 | |
fbf002bb DSH |
51 | if ($fnum > 2 && ! -d $dest) |
52 | { | |
53 | die "Destination must be a directory"; | |
54 | } | |
55 | ||
56 | foreach (@filelist) | |
57 | { | |
58 | if (-d $dest) | |
59 | { | |
60 | $dfile = $_; | |
61 | $dfile =~ s|^.*[/\\]([^/\\]*)$|$1|; | |
62 | $dfile = "$dest/$dfile"; | |
63 | } | |
64 | else | |
65 | { | |
66 | $dfile = $dest; | |
67 | } | |
68 | sysopen(IN, $_, O_RDONLY|O_BINARY) || die "Can't Open $_"; | |
69 | sysopen(OUT, $dfile, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY) | |
70 | || die "Can't Open $dfile"; | |
71 | while (sysread IN, $buf, 10240) | |
72 | { | |
7dbbd4b3 DSH |
73 | if ($stripcr) |
74 | { | |
75 | $buf =~ tr/\015//d; | |
76 | } | |
fbf002bb DSH |
77 | syswrite(OUT, $buf, length($buf)); |
78 | } | |
79 | close(IN); | |
80 | close(OUT); | |
81 | print "Copying: $_ to $dfile\n"; | |
82 | } | |
609b0852 | 83 | |
fbf002bb | 84 |