Prior to this point, anyone programming in perl who wanted to interact
with C programs, like the kernel, was forced to guess the layouts of
-the C strutures, and then hardwire these into his program. Of course,
+the C structures, and then hardwire these into his program. Of course,
when you took your wonderfully crafted program to a system where the
-sgtty structure was laid out differently, you program broke. Which is
+sgtty structure was laid out differently, your program broke. Which is
a shame.
We've had Larry's h2ph translator, which helped, but that only works on
$RCSID = '$Id: c2ph,v 1.7 95/10/28 10:41:47 tchrist Exp Locker: tchrist $';
+use File::Temp;
######################################################################
$indent = 2;
$CC = 'cc';
-$CFLAGS = '-g -S';
+!NO!SUBS!
+
+if (($Config{gccversion} || '') =~ /^(\d+)\.(\d+)/
+ and ($1 > 3 or ($1 == 3 and $2 >= 2))) {
+ print OUT q/$CFLAGS = '-gstabs -S';/;
+} else {
+ print OUT q/$CFLAGS = '-g -S';/;
+}
+
+print OUT <<'!NO!SUBS!';
+
$DEFINES = '';
$perl++ if $0 =~ m#/?c2ph$#;
require 'getopts.pl';
+use File::Temp 'tempdir';
+
eval '$'.$1.'$2;' while $ARGV[0] =~ /^([A-Za-z_]+=)(.*)/ && shift;
&Getopts('aixdpvtnws:') || &usage(0);
$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
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) {
}
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 {
- $TMP = "/tmp/c2ph.$$.c";
+ &safedir;
+ $TMP = "$SAFEDIR/c2ph.$$.c";
&system("cat @ARGV > $TMP") && exit 1;
- &system("cd /tmp; $CC $CFLAGS $DEFINES $TMP") && exit 1;
+ &system("cd $SAFEDIR && $CC $CFLAGS $DEFINES $TMP") && exit 1;
unlink $TMP;
$TMP =~ s/\.c$/.s/;
@ARGV = ($TMP);
}
sub compute_intrinsics {
- local($TMP) = "/tmp/c2ph-i.$$.c";
+ &safedir;
+ local($TMP) = "$SAFEDIR/c2ph-i.$$.c";
open (TMP, ">$TMP") || die "can't open $TMP: $!";
select(TMP);
close TMP;
select(STDOUT);
- open(PIPE, "cd /tmp && $CC $TMP && /tmp/a.out|");
+ open(PIPE, "cd $SAFEDIR && $CC $TMP && $SAFEDIR/a.out|");
while (<PIPE>) {
chop;
split(' ',$_,2);;
$intrinsics{$_[1]} = $template{$_[0]};
}
close(PIPE) || die "couldn't read intrinsics!";
- unlink($TMP, '/tmp/a.out');
+ unlink($TMP, '$SAFEDIR/a.out');
print STDERR "done\n" if $trace;
}