From owner-svn-src-all@FreeBSD.ORG Fri Jan 21 18:10:11 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 B84B4106566B; Fri, 21 Jan 2011 18:10:11 +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 A6FF08FC18; Fri, 21 Jan 2011 18:10:11 +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 p0LIABic062697; Fri, 21 Jan 2011 18:10:11 GMT (envelope-from fanf@svn.freebsd.org) Received: (from fanf@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id p0LIABph062695; Fri, 21 Jan 2011 18:10:11 GMT (envelope-from fanf@svn.freebsd.org) Message-Id: <201101211810.p0LIABph062695@svn.freebsd.org> From: Tony Finch Date: Fri, 21 Jan 2011 18:10:11 +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: r217698 - 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: Fri, 21 Jan 2011 18:10:11 -0000 Author: fanf Date: Fri Jan 21 18:10:11 2011 New Revision: 217698 URL: http://svn.freebsd.org/changeset/base/217698 Log: Update to upstrea version 2.5.6. Detect IO errors properly. Write #line directives to the correct output stream. 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 Fri Jan 21 17:53:40 2011 (r217697) +++ head/usr.bin/unifdef/unifdef.c Fri Jan 21 18:10:11 2011 (r217698) @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002 - 2010 Tony Finch + * Copyright (c) 2002 - 2011 Tony Finch * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -57,7 +57,7 @@ #include const char copyright[] = - "@(#) $Version: unifdef-2.5 $\n" + "@(#) $Version: unifdef-2.5.6.21f1388 $\n" "@(#) $FreeBSD$\n" "@(#) $Author: Tony Finch (dot@dotat.at) $\n" "@(#) $URL: http://dotat.at/prog/unifdef $\n" @@ -549,6 +549,7 @@ state(Ifstate is) /* * Write a line to the output or not, according to command line options. + * If writing fails, closeout() will print the error and exit. */ static void flushline(bool keep) @@ -561,21 +562,23 @@ flushline(bool keep) delcount += 1; blankcount += 1; } else { - if (lnnum && delcount > 0) - printf("#line %d%s", linenum, newline); - fputs(tline, output); + if (lnnum && delcount > 0 && + fprintf(output, "#line %d%s", linenum, newline) < 0) + closeout(); + if (fputs(tline, output) == EOF) + closeout(); delcount = 0; blankmax = blankcount = blankline ? blankcount + 1 : 0; } } else { - if (lnblank) - fputs(newline, output); + if (lnblank && fputs(newline, output) == EOF) + closeout(); exitstat = 1; delcount += 1; blankcount = 0; } - if (debugging) - fflush(output); + if (debugging && fflush(output) == EOF) + closeout(); } /* @@ -604,13 +607,13 @@ closeout(void) { if (symdepth && !zerosyms) printf("\n"); - if (fclose(output) == EOF) { - warn("couldn't write to %s", ofilename); + if (ferror(output) || fclose(output) == EOF) { if (overwriting) { + warn("couldn't write to temporary file"); unlink(tempname); - errx(2, "%s unchanged", filename); + errx(2, "%s unchanged", ofilename); } else { - exit(2); + err(2, "couldn't write to %s", ofilename); } } } @@ -647,8 +650,12 @@ parseline(void) Comment_state wascomment; linenum++; - if (fgets(tline, MAXLINE, input) == NULL) - return (LT_EOF); + if (fgets(tline, MAXLINE, input) == NULL) { + if (ferror(input)) + error(strerror(errno)); + else + return (LT_EOF); + } if (newline == NULL) { if (strrchr(tline, '\n') == strrchr(tline, '\r') + 1) newline = newline_crlf; @@ -722,7 +729,9 @@ parseline(void) if (linestate == LS_HASH) { size_t len = cp - tline; if (fgets(tline + len, MAXLINE - len, input) == NULL) { - /* append the missing newline */ + if (ferror(input)) + error(strerror(errno)); + /* append the missing newline at eof */ strcpy(tline + len, newline); cp += strlen(newline); linestate = LS_START;