From owner-freebsd-hackers Tue Nov 12 10:47:02 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id KAA13089 for hackers-outgoing; Tue, 12 Nov 1996 10:47:02 -0800 (PST) Received: from mail.cs.tu-berlin.de (mail.cs.tu-berlin.de [130.149.17.13]) by freefall.freebsd.org (8.7.5/8.7.3) with ESMTP id KAA13079 for ; Tue, 12 Nov 1996 10:46:30 -0800 (PST) Received: from campa.panke.de (anonymous214.ppp.cs.tu-berlin.de [130.149.17.214]) by mail.cs.tu-berlin.de (8.6.13/8.6.12) with ESMTP id TAA10034; Tue, 12 Nov 1996 19:25:42 +0100 Received: (from wosch@localhost) by campa.panke.de (8.6.12/8.6.12) id TAA00674; Tue, 12 Nov 1996 19:25:36 +0100 Date: Tue, 12 Nov 1996 19:25:36 +0100 From: Wolfram Schneider Message-Id: <199611121825.TAA00674@campa.panke.de> To: mark@linus.demon.co.uk (Mark Valentine), hackers@freebsd.org, Keith Bostic Subject: Re: cvs commit: src/share/doc/handbook porting.sgml ports.sgml In-Reply-To: <199611121304.OAA00453@campa.panke.de> References: <199611120404.EAA23202@janai.thuvia.org> <199611121304.OAA00453@campa.panke.de> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk Wolfram Schneider writes: >>> Jordan K. Hubbard writes: >>> >> I'm guessing sed, I thought Jordan had a disdain dislike for perl. :-) >>> > >>> >sed, definitely. I mean, who needs perl when you've already got >>> >sed, sh and awk? :-) >>> >>> Perl is 8 bit clean and can edit binary data. >>> >>> $ wc /kernel >>> 2379 24484 808608 /kernel >>> $ perl -npe 's,/sbin/,/SBIN/,g' /kernel | wc >>> 2379 24484 808608 /kernel >>> $ sed 's,/sbin/,/SBIN/,g' /kernel | wc >>> 67 753 29419 >> >>$ wc /kernel >> 3672 44913 1282638 /kernel >>$ /usr/gnu/bin/sed 's,/sbin/,/SBIN/,g' /kernel | wc >> 3672 44913 1282638 Ok, here is the patch. The problem occurs if a line *start* with character '\377'. C beginners bug, getc() return an int and not a char or unsigned char. Index: main.c =================================================================== RCS file: /usr/cvs/src/usr.bin/sed/main.c,v retrieving revision 1.3 diff -u -r1.3 main.c --- 1.3 1996/08/11 17:46:34 +++ main.c 1996/11/12 18:11:37 @@ -274,8 +274,7 @@ err(FATAL, "%s: %s", fname, strerror(errno)); } - if ((c = getc(f)) != EOF) { - (void)ungetc(c, f); + if (!feof(f)) { break; } (void)fclose(f); @@ -299,7 +298,7 @@ linenum++; /* Advance to next non-empty file */ - while ((c = getc(f)) == EOF) { + while (feof(f)) { (void)fclose(f); files = files->next; if (files == NULL) { @@ -315,7 +314,6 @@ err(FATAL, "%s: %s", fname, strerror(errno)); } } - (void)ungetc(c, f); return (1); }