Module Name: src Committed By: maya Date: Sat Jan 14 18:35:43 UTC 2017
Modified Files: src/bin/ksh: history.c Log Message: reorganize the code so we test if open fails at the open call. this doesn't actually make a functional difference as ftruncate can handle it, but it's a bit clearer and appeases static analyzers. ok riastradh To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/bin/ksh/history.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/bin/ksh/history.c diff -u src/bin/ksh/history.c:1.11 src/bin/ksh/history.c:1.12 --- src/bin/ksh/history.c:1.11 Wed Aug 31 16:24:54 2011 +++ src/bin/ksh/history.c Sat Jan 14 18:35:43 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: history.c,v 1.11 2011/08/31 16:24:54 plunky Exp $ */ +/* $NetBSD: history.c,v 1.12 2017/01/14 18:35:43 maya Exp $ */ /* * command history @@ -19,7 +19,7 @@ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: history.c,v 1.11 2011/08/31 16:24:54 plunky Exp $"); +__RCSID("$NetBSD: history.c,v 1.12 2017/01/14 18:35:43 maya Exp $"); #endif @@ -757,13 +757,14 @@ hist_finish() else hp = histlist; - fd = open(hname, O_WRONLY | O_CREAT | O_TRUNC | O_EXLOCK, 0777); - /* Remove anything written before we got the lock */ - ftruncate(fd, 0); - if (fd >= 0 && (fh = fdopen(fd, "w"))) { - for (i = 0; hp + i <= histptr && hp[i]; i++) - fprintf(fh, "%s%c", hp[i], '\0'); - fclose(fh); + if ((fd = open(hname, O_WRONLY | O_CREAT | O_TRUNC | O_EXLOCK, 0777)) != -1) { + /* Remove anything written before we got the lock */ + ftruncate(fd, 0); + if ((fh = fdopen(fd, "w")) != NULL) { + for (i = 0; hp + i <= histptr && hp[i]; i++) + fprintf(fh, "%s%c", hp[i], '\0'); + fclose(fh); + } } }