2 # Copyright 2013-2016 The OpenSSL Project Authors. All Rights Reserved.
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
13 # copy-if-different.pl
15 # Copy to the destination if the source is not the same as it.
19 foreach my $arg (@ARGV) {
20 $arg =~ s|\\|/|g; # compensate for bug/feature in cygwin glob...
21 foreach (glob qq("$arg"))
31 die "Need at least two filenames";
34 my $dest = pop @filelist;
36 if ($fnum > 2 && ! -d $dest)
38 die "Destination must be a directory";
47 $dfile =~ s|^.*[/\\]([^/\\]*)$|$1|;
48 $dfile = "$dest/$dfile";
58 sysopen(IN, $_, O_RDONLY|O_BINARY) || die "Can't Open $_";
59 sysopen(OUT, $dfile, O_RDONLY|O_BINARY)
60 || die "Can't Open $dfile";
61 while (sysread IN, $buf, 10240)
64 goto copy if !sysread(OUT, $b2, 10240) || $buf ne $b2;
66 goto copy if sysread(OUT, $buf, 1);
69 print "NOT copying: $_ to $dfile\n";
73 sysopen(IN, $_, O_RDONLY|O_BINARY) || die "Can't Open $_";
74 sysopen(OUT, $dfile, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY)
75 || die "Can't Open $dfile";
76 while (sysread IN, $buf, 10240)
78 syswrite(OUT, $buf, length($buf));
82 print "Copying: $_ to $dfile\n";