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