From owner-svn-src-all@FreeBSD.ORG Tue Jan 18 19:13:04 2011 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 187B61065670; Tue, 18 Jan 2011 19:13:04 +0000 (UTC) (envelope-from fanf@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id E192E8FC08; Tue, 18 Jan 2011 19:13:03 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id p0IJD3a9048620; Tue, 18 Jan 2011 19:13:03 GMT (envelope-from fanf@svn.freebsd.org) Received: (from fanf@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id p0IJD3dK048618; Tue, 18 Jan 2011 19:13:03 GMT (envelope-from fanf@svn.freebsd.org) Message-Id: <201101181913.p0IJD3dK048618@svn.freebsd.org> From: Tony Finch Date: Tue, 18 Jan 2011 19:13:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r217550 - head/usr.bin/unifdef X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Jan 2011 19:13:04 -0000 Author: fanf Date: Tue Jan 18 19:13:03 2011 New Revision: 217550 URL: http://svn.freebsd.org/changeset/base/217550 Log: Update to upstream version 2.3 Only significant change is to fix a bu when the output file overwrites the input when the input is redirected. Obtained from: http://dotat.at/prog/unifdef Modified: head/usr.bin/unifdef/unifdef.c Modified: head/usr.bin/unifdef/unifdef.c ============================================================================== --- head/usr.bin/unifdef/unifdef.c Tue Jan 18 17:55:24 2011 (r217549) +++ head/usr.bin/unifdef/unifdef.c Tue Jan 18 19:13:03 2011 (r217550) @@ -57,7 +57,7 @@ #include const char copyright[] = - "@(#) $Version: unifdef-2.3 $\n" + "@(#) $Version: unifdef-2.5 $\n" "@(#) $FreeBSD$\n" "@(#) $Author: Tony Finch (dot@dotat.at) $\n" "@(#) $URL: http://dotat.at/prog/unifdef $\n" @@ -329,16 +329,10 @@ main(int argc, char *argv[]) output = stdout; } else { struct stat ist, ost; - memset(&ist, 0, sizeof(ist)); - memset(&ost, 0, sizeof(ost)); - - if (fstat(fileno(input), &ist) != 0) - err(2, "can't fstat %s", filename); - if (stat(ofilename, &ost) != 0 && errno != ENOENT) - warn("can't stat %s", ofilename); - - overwriting = (ist.st_dev == ost.st_dev - && ist.st_ino == ost.st_ino); + if (stat(ofilename, &ost) == 0 && + fstat(fileno(input), &ist) == 0) + overwriting = (ist.st_dev == ost.st_dev + && ist.st_ino == ost.st_ino); if (overwriting) { const char *dirsep; int ofd; @@ -402,7 +396,8 @@ usage(void) * When we have processed a group that starts off with a known-false * #if/#elif sequence (which has therefore been deleted) followed by a * #elif that we don't understand and therefore must keep, we edit the - * latter into a #if to keep the nesting correct. + * latter into a #if to keep the nesting correct. We use strncpy() to + * overwrite the 4 byte token "elif" with "if " without a '\0' byte. * * When we find a true #elif in a group, the following block will * always be kept and the rest of the sequence after the next #elif or @@ -455,7 +450,7 @@ static void Oelif (void) { if (!iocccok) static void Idrop (void) { Fdrop(); ignoreon(); } static void Itrue (void) { Ftrue(); ignoreon(); } static void Ifalse(void) { Ffalse(); ignoreon(); } -/* edit this line */ +/* modify this line */ static void Mpass (void) { strncpy(keyword, "if ", 4); Pelif(); } static void Mtrue (void) { keywordedit("else"); state(IS_TRUE_MIDDLE); } static void Melif (void) { keywordedit("endif"); state(IS_FALSE_TRAILER); } @@ -629,10 +624,10 @@ done(void) if (incomment) error("EOF in comment"); closeout(); - if (overwriting && rename(tempname, filename) == -1) { + if (overwriting && rename(tempname, ofilename) == -1) { warn("couldn't rename temporary file"); unlink(tempname); - errx(2, "%s unchanged", filename); + errx(2, "%s unchanged", ofilename); } exit(exitstat); }