]> git.ipfire.org Git - thirdparty/openssl.git/blame - util/copy.pl
Copyright consolidation: perl files
[thirdparty/openssl.git] / util / copy.pl
CommitLineData
e0a65194
RS
1#! /usr/bin/env perl
2# Copyright 2005-2016 The OpenSSL Project Authors. All Rights Reserved.
3#
4# Licensed under the OpenSSL license (the "License"). You may not use
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
10use 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
18my $stripcr = 0;
19
fbf002bb
DSH
20my $arg;
21
22foreach $arg (@ARGV) {
7dbbd4b3
DSH
23 if ($arg eq "-stripcr")
24 {
25 $stripcr = 1;
26 next;
27 }
68e57536 28 $arg =~ s|\\|/|g; # compensate for bug/feature in cygwin glob...
fbf002bb
DSH
29 foreach (glob $arg)
30 {
31 push @filelist, $_;
32 }
33}
34
35$fnum = @filelist;
36
37if ($fnum <= 1)
38 {
39 die "Need at least two filenames";
40 }
41
42$dest = pop @filelist;
43
44if ($fnum > 2 && ! -d $dest)
45 {
46 die "Destination must be a directory";
47 }
48
49foreach (@filelist)
50 {
51 if (-d $dest)
52 {
53 $dfile = $_;
54 $dfile =~ s|^.*[/\\]([^/\\]*)$|$1|;
55 $dfile = "$dest/$dfile";
56 }
57 else
58 {
59 $dfile = $dest;
60 }
61 sysopen(IN, $_, O_RDONLY|O_BINARY) || die "Can't Open $_";
62 sysopen(OUT, $dfile, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY)
63 || die "Can't Open $dfile";
64 while (sysread IN, $buf, 10240)
65 {
7dbbd4b3
DSH
66 if ($stripcr)
67 {
68 $buf =~ tr/\015//d;
69 }
fbf002bb
DSH
70 syswrite(OUT, $buf, length($buf));
71 }
72 close(IN);
73 close(OUT);
74 print "Copying: $_ to $dfile\n";
75 }
76
77