Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/bin/ksh reorganize the code so we test if open fails at the ...
details: https://anonhg.NetBSD.org/src/rev/953072dde2ed
branches: trunk
changeset: 350615:953072dde2ed
user: maya <maya%NetBSD.org@localhost>
date: Sat Jan 14 18:35:43 2017 +0000
description:
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
diffstat:
bin/ksh/history.c | 19 ++++++++++---------
1 files changed, 10 insertions(+), 9 deletions(-)
diffs (40 lines):
diff -r 4533da98a1d1 -r 953072dde2ed bin/ksh/history.c
--- a/bin/ksh/history.c Sat Jan 14 17:17:53 2017 +0000
+++ b/bin/ksh/history.c Sat Jan 14 18:35:43 2017 +0000
@@ -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 @@
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);
+ }
}
}
Home |
Main Index |
Thread Index |
Old Index