Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/share/misc - EXIT_FAILURE instead of 1
details: https://anonhg.NetBSD.org/src/rev/b510b166fbfb
branches: trunk
changeset: 960765:b510b166fbfb
user: christos <christos%NetBSD.org@localhost>
date: Sun Mar 28 14:16:16 2021 +0000
description:
- EXIT_FAILURE instead of 1
- %j instead of PRI for *intmax_t
- != -1 instead of < 0 for syscalls
diffstat:
share/misc/style | 28 +++++++++++++++-------------
1 files changed, 15 insertions(+), 13 deletions(-)
diffs (65 lines):
diff -r 5f0c5fc473fc -r b510b166fbfb share/misc/style
--- a/share/misc/style Sun Mar 28 14:13:18 2021 +0000
+++ b/share/misc/style Sun Mar 28 14:16:16 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: style,v 1.60 2020/11/29 09:15:33 rillig Exp $ */
+/* $NetBSD: style,v 1.61 2021/03/28 14:16:16 christos Exp $ */
/*
* The revision control tag appears first, with a blank line after it.
@@ -30,7 +30,7 @@
#include <sys/cdefs.h>
__COPYRIGHT("@(#) Copyright (c) 2008\
The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: style,v 1.60 2020/11/29 09:15:33 rillig Exp $");
+__RCSID("$NetBSD: style,v 1.61 2021/03/28 14:16:16 christos Exp $");
/*
* VERY important single-line comments look like this.
@@ -380,11 +380,13 @@
* the change needs to be done in one place.
*
* Use err/warn(3), don't roll your own!
+ *
+ * Prefer EXIT_FAILURE instead of random error codes.
*/
if ((four = malloc(sizeof(*four))) == NULL)
- err(1, NULL);
+ err(EXIT_FAILURE, NULL);
if ((six = (int *)overflow()) == NULL)
- errx(1, "Number overflowed.");
+ errx(EXIT_FAILURE, "Number overflowed.");
/* No parentheses are needed around the return value. */
return eight;
@@ -408,21 +410,21 @@
_DIAGASSERT(p != NULL);
_DIAGASSERT(filedesc != -1);
- if (stat(p, sb) < 0)
- err(1, "Unable to stat %s", p);
+ /* Prefer checking syscalls against -1 instead of < 0 */
+ if (stat(p, sb) == -1)
+ err(EXIT_FAILURE, "Unable to stat %s", p);
/*
- * To printf quantities that might be larger than "long", include
- * <inttypes.h>, cast quantities to intmax_t or uintmax_t and use
- * PRI?MAX constants.
+ * To printf quantities that might be larger than "long",
+ * cast quantities to intmax_t or uintmax_t and use %j
*/
- (void)printf("The size of %s is %" PRIdMAX " (%#" PRIxMAX ")\n", p,
+ (void)printf("The size of %s is %jd (%#ju)\n", p,
(intmax_t)sb->st_size, (uintmax_t)sb->st_size);
/*
- * To printf quantities of known bit-width, use the corresponding
- * defines (generally only done within NetBSD for quantities that
- * exceed 32-bits).
+ * To printf quantities of known bit-width, include <inttypes.h> and
+ * use the corresponding defines (generally only done within NetBSD
+ * for quantities that exceed 32-bits).
*/
(void)printf("%s uses %" PRId64 " blocks and has flags %#" PRIx32 "\n",
p, sb->st_blocks, sb->st_flags);
Home |
Main Index |
Thread Index |
Old Index