Date: Wed, 15 Dec 2004 03:46:01 -0800 From: Alfred Perlstein <alfred@freebsd.org> To: Suleiman Souhlal <ssouhlal@FreeBSD.org> Cc: cvs-all@FreeBSD.org Subject: Re: cvs commit: src/usr.bin/rev rev.c Message-ID: <20041215114601.GP15799@elvis.mu.org> In-Reply-To: <200412150624.iBF6Ov1u016707@repoman.freebsd.org> References: <200412150624.iBF6Ov1u016707@repoman.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
* Suleiman Souhlal <ssouhlal@FreeBSD.org> [041214 22:24] wrote: > ssouhlal 2004-12-15 06:24:57 UTC > > FreeBSD src repository > > Modified files: > usr.bin/rev rev.c > Log: > If ferror is true, we must reset the error indicator. There's another possible bug here. Note that the code seems to unconditionally emit an EOL marker even if the last character of the line is not a newline. If that is a bug then here is a possible fix: something like this may work: (untested) Index: rev.c =================================================================== RCS file: /home/ncvs/src/usr.bin/rev/rev.c,v retrieving revision 1.8 diff -u -r1.8 rev.c --- rev.c 15 Dec 2004 06:24:57 -0000 1.8 +++ rev.c 15 Dec 2004 11:44:48 -0000 @@ -66,7 +66,7 @@ wchar_t *p, *t; FILE *fp; size_t len; - int ch, rval; + int ch, rval, newline; setlocale(LC_ALL, ""); @@ -94,12 +94,17 @@ filename = *argv++; } while ((p = fgetwln(fp, &len)) != NULL) { - if (p[len - 1] == '\n') + if (p[len - 1] == '\n') { + newline = 1; --len; + } else { + newline = 0; + } t = p + len - 1; for (t = p + len - 1; t >= p; --t) putwchar(*t); - putwchar('\n'); + if (newline) + putwchar('\n'); } if (ferror(fp)) { warn("%s", filename); -- - Alfred Perlstein - Research Engineering Development Inc. - email: bright@mu.org cell: 408-480-4684
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20041215114601.GP15799>