[klibc] [PATCH] let klcc pass input from STDIN to gcc

Daniel Thaler daniel at dthaler.de
Fri May 20 03:16:11 PDT 2005


Some packages want to pass input to gcc via STDIN (iptables for example)

This patch lets klcc accept '-' as a valid input filename, prevents it
from setting -x in that case and changes the invocation of gcc from
system() to open3() so that gcc's STDIN can be connected to klcc's STDIN.

Daniel Thaler
-------------- next part --------------
--- klibc-1.0.8/klcc.in.old	2005-05-20 03:51:12.000000000 -0600
+++ klibc-1.0.8/klcc.in	2005-05-20 03:52:03.000000000 -0600
@@ -1,5 +1,7 @@
 # -*- perl -*-
 
+use IPC::Open3;
+
 # Standard includes
 @includes = ("-I${prefix}/${KCROSS}include/arch/${ARCH}",
 	     "-I${prefix}/${KCROSS}include/bits${BITSIZE}",
@@ -57,7 +59,7 @@
 
 	# Skip object files
 	if ( $need ne 'obj' ) {
-	    unless ( $xopt eq $need ) {
+	    unless ( $xopt eq $need || $need eq 'stdin') {
 		push(@as, '-x', $need);
 		$xopt = $need;
 	    }
@@ -79,7 +81,10 @@
 # Run a program; printing out the command line if $verbose is set
 sub mysystem(@) {
     print STDERR join(' ', @_), "\n" if ( $verbose );
-    return system(@_);
+    my $cmd = shift;
+    my $childpid = open3("<&STDIN", ">&STDOUT", ">&STDERR", $cmd, @_);
+    waitpid ($childpid, 0);
+    return $?;
 }
 
 #
@@ -117,6 +122,11 @@
 	# Not an option.  Must be a filename then.
 	push(@files, $a);
 	$flang{$a} = $lang || filename2lang($a);
+    } elsif ( $a eq '-' ) {
+	# gcc gets its input from stdin
+	push(@files, $a);
+	# prevent setting -x
+	$flang{$a} = 'stdin'
     } elsif ( $a =~ /^-print-klibc-(.*)$/ ) {
 	# This test must precede -print
 	if ( defined($conf{$1}) ) {


More information about the klibc mailing list