commit 5a7ce9d3017394a673f6babd691d6aad44af4e75
parent 31f2dabebb6497a6b69a5f319c3772e7cf5f019c
Author: Stephen Gregoratto <dev@sgregoratto.me>
Date: Mon, 19 Oct 2020 16:44:17 +1100
Sync oconfigure
Diffstat:
M | compats.c | | | 83 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- |
M | configure | | | 8 | +++++++- |
M | tests.c | | | 4 | ++++ |
3 files changed, 86 insertions(+), 9 deletions(-)
diff --git a/compats.c b/compats.c
@@ -41,6 +41,18 @@ vwarnx(const char *fmt, va_list ap)
fprintf(stderr, "%s: ", getprogname());
if (fmt != NULL)
vfprintf(stderr, fmt, ap);
+ fprintf(stderr, "\n");
+}
+
+void
+vwarnc(int code, const char *fmt, va_list ap)
+{
+ fprintf(stderr, "%s: ", getprogname());
+ if (fmt != NULL) {
+ vfprintf(stderr, fmt, ap);
+ fprintf(stderr, ": ");
+ }
+ fprintf(stderr, "%s\n", strerror(code));
}
void
@@ -49,10 +61,49 @@ vwarn(const char *fmt, va_list ap)
int sverrno;
sverrno = errno;
- vwarnx(fmt, ap);
+ fprintf(stderr, "%s: ", getprogname());
+ if (fmt != NULL) {
+ vfprintf(stderr, fmt, ap);
+ fprintf(stderr, ": ");
+ }
+ fprintf(stderr, "%s\n", strerror(sverrno));
+}
+
+void
+verrc(int eval, int code, const char *fmt, va_list ap)
+{
+ fprintf(stderr, "%s: ", getprogname());
+ if (fmt != NULL) {
+ vfprintf(stderr, fmt, ap);
+ fprintf(stderr, ": ");
+ }
+ fprintf(stderr, "%s\n", strerror(code));
+ exit(eval);
+}
+
+void
+verrx(int eval, const char *fmt, va_list ap)
+{
+ fprintf(stderr, "%s: ", getprogname());
if (fmt != NULL)
- fputs(": ", stderr);
+ vfprintf(stderr, fmt, ap);
+ fprintf(stderr, "\n");
+ exit(eval);
+}
+
+void
+verr(int eval, const char *fmt, va_list ap)
+{
+ int sverrno;
+
+ sverrno = errno;
+ fprintf(stderr, "%s: ", getprogname());
+ if (fmt != NULL) {
+ vfprintf(stderr, fmt, ap);
+ fprintf(stderr, ": ");
+ }
fprintf(stderr, "%s\n", strerror(sverrno));
+ exit(eval);
}
void
@@ -61,9 +112,18 @@ err(int eval, const char *fmt, ...)
va_list ap;
va_start(ap, fmt);
- vwarn(fmt, ap);
+ verr(eval, fmt, ap);
+ va_end(ap);
+}
+
+void
+errc(int eval, int code, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ verrc(eval, code, fmt, ap);
va_end(ap);
- exit(eval);
}
void
@@ -72,10 +132,8 @@ errx(int eval, const char *fmt, ...)
va_list ap;
va_start(ap, fmt);
- vwarnx(fmt, ap);
+ verrx(eval, fmt, ap);
va_end(ap);
- fputc('\n', stderr);
- exit(eval);
}
void
@@ -89,6 +147,16 @@ warn(const char *fmt, ...)
}
void
+warnc(int code, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ vwarnc(code, fmt, ap);
+ va_end(ap);
+}
+
+void
warnx(const char *fmt, ...)
{
va_list ap;
@@ -96,7 +164,6 @@ warnx(const char *fmt, ...)
va_start(ap, fmt);
vwarnx(fmt, ap);
va_end(ap);
- fputc('\n', stderr);
}
#endif /* !HAVE_ERR */
#if !HAVE_B64_NTOP
diff --git a/configure b/configure
@@ -15,7 +15,7 @@
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-OCONFIGURE_VERSION="0.2.5"
+OCONFIGURE_VERSION="0.2.6"
#
# This script outputs two files: config.h and Makefile.configure.
@@ -627,10 +627,16 @@ __HEREDOC__
* Compatibility functions for err(3).
*/
extern void err(int, const char *, ...);
+extern void errc(int, int, const char *, ...);
extern void errx(int, const char *, ...);
+extern void verr(int, const char *, va_list);
+extern void verrc(int, int, const char *, va_list);
+extern void verrx(int, const char *, va_list);
extern void warn(const char *, ...);
extern void warnx(const char *, ...);
+extern void warnc(int, const char *, ...);
extern void vwarn(const char *, va_list);
+extern void vwarnc(int, const char *, va_list);
extern void vwarnx(const char *, va_list);
__HEREDOC__
diff --git a/tests.c b/tests.c
@@ -93,13 +93,17 @@ main(void)
*/
#include <err.h>
+#include <errno.h>
int
main(void)
{
warnx("%d. warnx", 1);
+ warnc(ENOENT, "%d. warn", ENOENT);
warn("%d. warn", 2);
err(0, "%d. err", 3);
+ errx(0, "%d. err", 3);
+ errc(0, ENOENT, "%d. err", 3);
/* NOTREACHED */
return 1;
}