summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/util/mklink.pl
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lib/libcrypto/util/mklink.pl73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/lib/libcrypto/util/mklink.pl b/src/lib/libcrypto/util/mklink.pl
new file mode 100644
index 0000000000..182732d959
--- /dev/null
+++ b/src/lib/libcrypto/util/mklink.pl
@@ -0,0 +1,73 @@
1#!/usr/local/bin/perl
2
3# mklink.pl
4
5# The first command line argument is a non-empty relative path
6# specifying the "from" directory.
7# Each other argument is a file name not containing / and
8# names a file in the current directory.
9#
10# For each of these files, we create in the "from" directory a link
11# of the same name pointing to the local file.
12#
13# We assume that the directory structure is a tree, i.e. that it does
14# not contain symbolic links and that the parent of / is never referenced.
15# Apart from this, this script should be able to handle even the most
16# pathological cases.
17#
18
19use Cwd;
20
21my $from = shift;
22my @files = @ARGV;
23
24my @from_path = split(/[\\\/]/, $from);
25my $pwd = getcwd();
26chomp($pwd);
27my @pwd_path = split(/[\\\/]/, $pwd);
28
29my @to_path = ();
30
31my $dirname;
32foreach $dirname (@from_path) {
33
34 # In this loop, @to_path always is a relative path from
35 # @pwd_path (interpreted is an absolute path) to the original pwd.
36
37 # At the end, @from_path (as a relative path from the original pwd)
38 # designates the same directory as the absolute path @pwd_path,
39 # which means that @to_path then is a path from there to the original pwd.
40
41 next if ($dirname eq "" || $dirname eq ".");
42
43 if ($dirname eq "..") {
44 @to_path = (pop(@pwd_path), @to_path);
45 } else {
46 @to_path = ("..", @to_path);
47 push(@pwd_path, $dirname);
48 }
49}
50
51my $to = join('/', @to_path);
52
53my $file;
54$symlink_exists=eval {symlink("",""); 1};
55foreach $file (@files) {
56 my $err = "";
57 if ($symlink_exists) {
58 unlink "$from/$file";
59 symlink("$to/$file", "$from/$file") or $err = " [$!]";
60 } else {
61 unlink "$from/$file";
62 open (OLD, "<$file") or die "Can't open $file: $!";
63 open (NEW, ">$from/$file") or die "Can't open $from/$file: $!";
64 binmode(OLD);
65 binmode(NEW);
66 while (<OLD>) {
67 print NEW $_;
68 }
69 close (OLD) or die "Can't close $file: $!";
70 close (NEW) or die "Can't close $from/$file: $!";
71 }
72 print $file . " => $from/$file$err\n";
73}