summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2018-12-27 13:02:15 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2018-12-27 13:02:15 +0000
commitcd49e866fcf9b07db5e0e79c2ed8b07e4e21a9c1 (patch)
tree0da004c533fd2d244e46f7f695698860bfa58adc
parent2cb73efc0d44459b82fcdc362d9878e560291403 (diff)
Notes
-rw-r--r--lib/libc/gen/errlst.c64
-rw-r--r--lib/libc/include/errlst.h2
-rw-r--r--lib/libc/string/strerror.c15
3 files changed, 71 insertions, 10 deletions
diff --git a/lib/libc/gen/errlst.c b/lib/libc/gen/errlst.c
index c75a7a8405d2b..648cbd422fe6e 100644
--- a/lib/libc/gen/errlst.c
+++ b/lib/libc/gen/errlst.c
@@ -33,9 +33,12 @@
__SCCSID("@(#)errlst.c 8.2 (Berkeley) 11/16/93");
__FBSDID("$FreeBSD$");
+#include <errno.h>
#include <stdio.h>
#include "errlst.h"
+const char __uprefix[] = "Unknown error";
+
const char *const sys_errlist[] = {
"No error: 0", /* 0 - ENOERROR */
"Operation not permitted", /* 1 - EPERM */
@@ -155,8 +158,67 @@ const char *const sys_errlist[] = {
"Not permitted in capability mode", /* 94 - ECAPMODE */
"State not recoverable", /* 95 - ENOTRECOVERABLE */
"Previous owner died", /* 96 - EOWNERDEAD */
+
+/*
+ * Reserved space in sys_errlist, take the next slot for a next error code.
+ * Reserve prevents the array size from changing for some time.
+ */
+ __uprefix, /* 97 */
+ __uprefix, /* 98 */
+ __uprefix, /* 99 */
+ __uprefix, /* 100 */
+ __uprefix, /* 101 */
+ __uprefix, /* 102 */
+ __uprefix, /* 103 */
+ __uprefix, /* 104 */
+ __uprefix, /* 105 */
+ __uprefix, /* 106 */
+ __uprefix, /* 107 */
+ __uprefix, /* 108 */
+ __uprefix, /* 109 */
+ __uprefix, /* 110 */
+ __uprefix, /* 111 */
+ __uprefix, /* 112 */
+ __uprefix, /* 113 */
+ __uprefix, /* 114 */
+ __uprefix, /* 115 */
+ __uprefix, /* 116 */
+ __uprefix, /* 117 */
+ __uprefix, /* 118 */
+ __uprefix, /* 119 */
+ __uprefix, /* 120 */
+ __uprefix, /* 121 */
+ __uprefix, /* 122 */
+ __uprefix, /* 123 */
+ __uprefix, /* 124 */
+ __uprefix, /* 125 */
+ __uprefix, /* 126 */
+ __uprefix, /* 127 */
+ __uprefix, /* 128 */
+ __uprefix, /* 129 */
+ __uprefix, /* 130 */
+ __uprefix, /* 131 */
+ __uprefix, /* 132 */
+ __uprefix, /* 133 */
+ __uprefix, /* 134 */
+ __uprefix, /* 135 */
+ __uprefix, /* 136 */
+ __uprefix, /* 137 */
+ __uprefix, /* 138 */
+ __uprefix, /* 139 */
+ __uprefix, /* 140 */
+ __uprefix, /* 141 */
+ __uprefix, /* 142 */
+ __uprefix, /* 143 */
+ __uprefix, /* 144 */
+ __uprefix, /* 145 */
+ __uprefix, /* 146 */
+ __uprefix, /* 147 */
+ __uprefix, /* 148 */
+ __uprefix, /* 149 */
+ __uprefix, /* 150 */
};
-const int sys_nerr = sizeof(sys_errlist) / sizeof(sys_errlist[0]);
+const int sys_nerr = ELAST + 1;
#ifdef PIC
__strong_reference(sys_errlist, __hidden_sys_errlist);
diff --git a/lib/libc/include/errlst.h b/lib/libc/include/errlst.h
index 3834524fb87b9..99492f840da56 100644
--- a/lib/libc/include/errlst.h
+++ b/lib/libc/include/errlst.h
@@ -42,4 +42,6 @@ extern const int __hidden_sys_nerr __hidden;
#define __hidden_sys_nerr sys_nerr
#endif
+extern const char __uprefix[] __hidden;
+
#endif /* __ERRLST_H__ */
diff --git a/lib/libc/string/strerror.c b/lib/libc/string/strerror.c
index c5ac55ed3bc1e..be3732d5b9e34 100644
--- a/lib/libc/string/strerror.c
+++ b/lib/libc/string/strerror.c
@@ -46,15 +46,12 @@ __FBSDID("$FreeBSD$");
#include "errlst.h"
-#define UPREFIX "Unknown error"
-
/*
- * Define a buffer size big enough to describe a 64-bit signed integer
- * converted to ASCII decimal (19 bytes), with an optional leading sign
- * (1 byte); finally, we get the prefix, delimiter (": ") and a trailing
- * NUL from UPREFIX.
+ * Define buffer big enough to contain delimiter (": ", 2 bytes),
+ * 64-bit signed integer converted to ASCII decimal (19 bytes) with
+ * optional leading sign (1 byte), and a trailing NUL.
*/
-#define EBUFSIZE (20 + 2 + sizeof(UPREFIX))
+#define EBUFSIZE (2 + 19 + 1 + 1)
/*
* Doing this by hand instead of linking with stdio(3) avoids bloat for
@@ -94,9 +91,9 @@ strerror_r(int errnum, char *strerrbuf, size_t buflen)
if (errnum < 0 || errnum >= __hidden_sys_nerr) {
errstr(errnum,
#if defined(NLS)
- catgets(catd, 1, 0xffff, UPREFIX),
+ catgets(catd, 1, 0xffff, __uprefix),
#else
- UPREFIX,
+ __uprefix,
#endif
strerrbuf, buflen);
retval = EINVAL;