This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Deprecate timelocal.pl with a warning
[perl5.git] / utils / c2ph.PL
index 91ecc04..39545e3 100644 (file)
@@ -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;
 
 ######################################################################
 
@@ -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 (<PIPE>) {
        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;