Lines 280-285
Link Here
|
280 |
|
280 |
|
281 |
$RCSID = '$Id: c2ph,v 1.7 95/10/28 10:41:47 tchrist Exp Locker: tchrist $'; |
281 |
$RCSID = '$Id: c2ph,v 1.7 95/10/28 10:41:47 tchrist Exp Locker: tchrist $'; |
282 |
|
282 |
|
|
|
283 |
use File::Temp; |
283 |
|
284 |
|
284 |
###################################################################### |
285 |
###################################################################### |
285 |
|
286 |
|
Lines 480-485
Link Here
|
480 |
printf "%-16s%-15s %s\n", $var, eval "\$$var", $msg; |
481 |
printf "%-16s%-15s %s\n", $var, eval "\$$var", $msg; |
481 |
} |
482 |
} |
482 |
|
483 |
|
|
|
484 |
sub safedir { |
485 |
$SAFEDIR = File::Temp::tempdir("c2ph.XXXXXX", TMPDIR => 1, CLEANUP => 1) |
486 |
unless (defined($SAFEDIR)); |
487 |
} |
488 |
|
489 |
undef $SAFEDIR; |
490 |
|
483 |
$recurse = 1; |
491 |
$recurse = 1; |
484 |
|
492 |
|
485 |
if (@ARGV) { |
493 |
if (@ARGV) { |
Lines 495-509
Link Here
|
495 |
} |
503 |
} |
496 |
elsif (@ARGV == 1 && $ARGV[0] =~ /\.c$/) { |
504 |
elsif (@ARGV == 1 && $ARGV[0] =~ /\.c$/) { |
497 |
local($dir, $file) = $ARGV[0] =~ m#(.*/)?(.*)$#; |
505 |
local($dir, $file) = $ARGV[0] =~ m#(.*/)?(.*)$#; |
498 |
$chdir = "cd $dir; " if $dir; |
506 |
$chdir = "cd $dir && " if $dir; |
499 |
&system("$chdir$CC $CFLAGS $DEFINES $file") && exit 1; |
507 |
&system("$chdir$CC $CFLAGS $DEFINES $file") && exit 1; |
500 |
$ARGV[0] =~ s/\.c$/.s/; |
508 |
$ARGV[0] =~ s/\.c$/.s/; |
501 |
} |
509 |
} |
502 |
else { |
510 |
else { |
503 |
$TMPDIR = tempdir(CLEANUP => 1); |
511 |
&safedir; |
504 |
$TMP = "$TMPDIR/c2ph.$$.c"; |
512 |
$TMP = "$SAFEDIR/c2ph.$$.c"; |
505 |
&system("cat @ARGV > $TMP") && exit 1; |
513 |
&system("cat @ARGV > $TMP") && exit 1; |
506 |
&system("cd $TMPDIR; $CC $CFLAGS $DEFINES $TMP") && exit 1; |
514 |
&system("cd $SAFEDIR && $CC $CFLAGS $DEFINES $TMP") && exit 1; |
507 |
unlink $TMP; |
515 |
unlink $TMP; |
508 |
$TMP =~ s/\.c$/.s/; |
516 |
$TMP =~ s/\.c$/.s/; |
509 |
@ARGV = ($TMP); |
517 |
@ARGV = ($TMP); |
Lines 1274-1281
Link Here
|
1274 |
} |
1282 |
} |
1275 |
|
1283 |
|
1276 |
sub compute_intrinsics { |
1284 |
sub compute_intrinsics { |
1277 |
$TMPDIR ||= tempdir(CLEANUP => 1); |
1285 |
&safedir; |
1278 |
local($TMP) = "$TMPDIR/c2ph-i.$$.c"; |
1286 |
local($TMP) = "$SAFEDIR/c2ph-i.$$.c"; |
1279 |
open (TMP, ">$TMP") || die "can't open $TMP: $!"; |
1287 |
open (TMP, ">$TMP") || die "can't open $TMP: $!"; |
1280 |
select(TMP); |
1288 |
select(TMP); |
1281 |
|
1289 |
|
Lines 1303-1309
Link Here
|
1303 |
close TMP; |
1311 |
close TMP; |
1304 |
|
1312 |
|
1305 |
select(STDOUT); |
1313 |
select(STDOUT); |
1306 |
open(PIPE, "cd $TMPDIR && $CC $TMP && $TMPDIR/a.out|"); |
1314 |
open(PIPE, "cd $SAFEDIR && $CC $TMP && $SAFEDIR/a.out|"); |
1307 |
while (<PIPE>) { |
1315 |
while (<PIPE>) { |
1308 |
chop; |
1316 |
chop; |
1309 |
split(' ',$_,2);; |
1317 |
split(' ',$_,2);; |
Lines 1312-1318
Link Here
|
1312 |
$intrinsics{$_[1]} = $template{$_[0]}; |
1320 |
$intrinsics{$_[1]} = $template{$_[0]}; |
1313 |
} |
1321 |
} |
1314 |
close(PIPE) || die "couldn't read intrinsics!"; |
1322 |
close(PIPE) || die "couldn't read intrinsics!"; |
1315 |
unlink($TMP, '$TMPDIR/a.out'); |
1323 |
unlink($TMP, '$SAFEDIR/a.out'); |
1316 |
print STDERR "done\n" if $trace; |
1324 |
print STDERR "done\n" if $trace; |
1317 |
} |
1325 |
} |
1318 |
|
1326 |
|