X-Git-Url: https://perl5.git.perl.org/perl5.git/blobdiff_plain/0e488909c71aa4d1cc21ed7dbfb5b99551c99af1..207e3571322a904190689eec9279f6c8b80caf7e:/utils/c2ph.PL diff --git a/utils/c2ph.PL b/utils/c2ph.PL index 91ecc04..13389ec 100644 --- a/utils/c2ph.PL +++ b/utils/c2ph.PL @@ -280,6 +280,7 @@ Anyway, here it is. Should run on perl v4 or greater. Maybe less. $RCSID = '$Id: c2ph,v 1.7 95/10/28 10:41:47 tchrist Exp Locker: tchrist $'; +use File::Temp; ###################################################################### @@ -368,13 +369,13 @@ $DEFINES = ''; $perl++ if $0 =~ m#/?c2ph$#; -require 'getopts.pl'; +use Getopt::Std qw(getopts); use File::Temp 'tempdir'; eval '$'.$1.'$2;' while $ARGV[0] =~ /^([A-Za-z_]+=)(.*)/ && shift; -&Getopts('aixdpvtnws:') || &usage(0); +getopts('aixdpvtnws:') || &usage(0); $opt_d && $debug++; $opt_t && $trace++; @@ -393,7 +394,7 @@ eval '$'.$1.'$2;' while $ARGV[0] =~ /^([A-Za-z_]+=)(.*)/ && shift; sub PLUMBER { select(STDERR); - print "oops, apperent pager foulup\n"; + print "oops, apparent pager foulup\n"; $isatty++; &usage(1); } @@ -467,7 +468,7 @@ EOF $CC $CFLAGS $DEFINES and the resulting *.s groped for stab information. If no files are supplied, then stdin is read directly with the assumption that it - contains stab information. All other liens will be ignored. At + contains stab information. All other lines will be ignored. At most one *.s file should be supplied. EOF @@ -480,6 +481,13 @@ sub defvar { printf "%-16s%-15s %s\n", $var, eval "\$$var", $msg; } +sub safedir { + $SAFEDIR = File::Temp::tempdir("c2ph.XXXXXX", TMPDIR => 1, CLEANUP => 1) + unless (defined($SAFEDIR)); +} + +undef $SAFEDIR; + $recurse = 1; if (@ARGV) { @@ -495,15 +503,15 @@ if (@ARGV) { } elsif (@ARGV == 1 && $ARGV[0] =~ /\.c$/) { local($dir, $file) = $ARGV[0] =~ m#(.*/)?(.*)$#; - $chdir = "cd $dir; " if $dir; + $chdir = "cd $dir && " if $dir; &system("$chdir$CC $CFLAGS $DEFINES $file") && exit 1; $ARGV[0] =~ s/\.c$/.s/; } else { - $TMPDIR = tempdir(CLEANUP => 1); - $TMP = "$TMPDIR/c2ph.$$.c"; + &safedir; + $TMP = "$SAFEDIR/c2ph.$$.c"; &system("cat @ARGV > $TMP") && exit 1; - &system("cd $TMPDIR; $CC $CFLAGS $DEFINES $TMP") && exit 1; + &system("cd $SAFEDIR && $CC $CFLAGS $DEFINES $TMP") && exit 1; unlink $TMP; $TMP =~ s/\.c$/.s/; @ARGV = ($TMP); @@ -1274,8 +1282,8 @@ sub fetch_template { } sub compute_intrinsics { - $TMPDIR ||= tempdir(CLEANUP => 1); - local($TMP) = "$TMPDIR/c2ph-i.$$.c"; + &safedir; + local($TMP) = "$SAFEDIR/c2ph-i.$$.c"; open (TMP, ">$TMP") || die "can't open $TMP: $!"; select(TMP); @@ -1303,7 +1311,7 @@ EOF close TMP; select(STDOUT); - open(PIPE, "cd $TMPDIR && $CC $TMP && $TMPDIR/a.out|"); + open(PIPE, "cd $SAFEDIR && $CC $TMP && $SAFEDIR/a.out|"); while () { chop; split(' ',$_,2);; @@ -1312,7 +1320,7 @@ EOF $intrinsics{$_[1]} = $template{$_[0]}; } close(PIPE) || die "couldn't read intrinsics!"; - unlink($TMP, '$TMPDIR/a.out'); + unlink($TMP, "$SAFEDIR/a.out"); print STDERR "done\n" if $trace; } @@ -1427,9 +1435,9 @@ sub repeat_template { close OUT or die "Can't close $file: $!"; chmod 0755, $file or die "Can't reset permissions for $file: $!\n"; unlink 'pstruct'; -print "Linking c2ph to pstruct.\n"; +print "Linking $file to pstruct.\n"; if (defined $Config{d_link}) { - link 'c2ph', 'pstruct'; + link $file, 'pstruct'; } else { unshift @INC, '../lib'; require File::Copy;