Subject: Re: bin/29659: awk handling of END non-portable
To: None <gnats-admin@netbsd.org>
From: Havard Eidnes <he@netbsd.org>
List: netbsd-bugs
Date: 03/11/2005 17:11:12
Here is a candidate patch, not much tested up and above that it
does work with the given test case.

- Havard

Index: lib.c
===================================================================
RCS file: /cvsroot/src/dist/nawk/lib.c,v
retrieving revision 1.5
diff -u -r1.5 lib.c
--- lib.c	26 Oct 2003 11:34:23 -0000	1.5
+++ lib.c	11 Mar 2005 16:09:24 -0000
@@ -106,7 +106,8 @@
 	int c;
 	static int firsttime = 1;
 	uschar *buf = *pbuf;
-	int bufsize = *pbufsize;
+	uschar save;
+	int bufsize = *pbufsize, savebufsize = *pbufsize;
 
 	if (firsttime) {
 		firsttime = 0;
@@ -118,6 +119,7 @@
 		donefld = 0;
 		donerec = 1;
 	}
+	save = buf[0];
 	buf[0] = 0;
 	while (argno < *ARGC || infile == stdin) {
 		   dprintf( ("argno=%d, file=|%s|\n", argno, file) );
@@ -164,8 +166,9 @@
 		infile = NULL;
 		argno++;
 	}
+	buf[0] = save;
 	*pbuf = buf;
-	*pbufsize = bufsize;
+	*pbufsize = savebufsize;
 	return 0;	/* true end of file */
 }