include/openssl/x509v3.h: restore previous stack definition arrangement
[openssl.git] / util / wrap.pl
1 #! /usr/bin/env perl
2
3 use strict;
4 use warnings;
5
6 use File::Basename;
7 use File::Spec::Functions;
8
9 my $there = canonpath(catdir(dirname($0), updir()));
10 my $std_engines = catdir($there, 'engines');
11 my $std_providers = catdir($there, 'providers');
12 my $unix_shlib_wrap = catfile($there, 'util/shlib_wrap.sh');
13
14 $ENV{OPENSSL_ENGINES} = $std_engines
15     if ($ENV{OPENSSL_ENGINES} // '') eq '' && -d $std_engines;
16 $ENV{OPENSSL_MODULES} = $std_providers
17     if ($ENV{OPENSSL_MODULES} // '') eq '' && -d $std_providers;
18
19 my $use_system = 0;
20 my @cmd;
21
22 if (-x $unix_shlib_wrap) {
23     @cmd = ( $unix_shlib_wrap, @ARGV );
24 } else {
25     # Hope for the best
26     @cmd = ( @ARGV );
27 }
28
29 # The exec() statement on MSWin32 doesn't seem to give back the exit code
30 # from the call, so we resort to using system() instead.
31 my $waitcode = system @cmd;
32
33 # According to documentation, -1 means that system() couldn't run the command,
34 # otherwise, the value is similar to the Unix wait() status value
35 # (exitcode << 8 | signalcode)
36 die "wrap.pl: Failed to execute '", join(' ', @cmd), "': $!\n"
37     if $waitcode == -1;
38
39 # When the subprocess aborted on a signal, mimic what Unix shells do, by
40 # converting the signal code to an exit code by setting the high bit.
41 # This only happens on Unix flavored operating systems, the others don't
42 # have this sort of signaling to date, and simply leave the low byte zero.
43 exit(($? & 255) | 128) if ($? & 255) != 0;
44
45 # When not a signal, just shift down the subprocess exit code and use that.
46 exit($? >> 8);