From 1b4b90160939cc7d8d74e6975e85a64f9c258394 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Fri, 3 Aug 2012 09:33:24 +0000 Subject: [PATCH] re_types.h: move errno values to above 200 print.c: add support for %m to describe error values (similar to syslog) --- include/re_types.h | 38 +++++++++++++++++++------------------- src/fmt/print.c | 9 +++++++++ 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/include/re_types.h b/include/re_types.h index 4196d14..f43cd4e 100644 --- a/include/re_types.h +++ b/include/re_types.h @@ -145,90 +145,90 @@ typedef bool _Bool; /** No data available */ #ifndef ENODATA -#define ENODATA 61 +#define ENODATA 200 #endif /** Protocol error */ #ifndef EPROTO -#define EPROTO 71 +#define EPROTO 201 #endif /** Not a data message */ #ifndef EBADMSG -#define EBADMSG 74 +#define EBADMSG 202 #endif /** Value too large for defined data type */ #ifndef EOVERFLOW -#define EOVERFLOW 75 +#define EOVERFLOW 203 #endif /** Accessing a corrupted shared library */ #ifndef ELIBBAD -#define ELIBBAD 80 +#define ELIBBAD 204 #endif /** Destination address required */ #ifndef EDESTADDRREQ -#define EDESTADDRREQ 89 +#define EDESTADDRREQ 205 #endif /** Protocol not supported */ #ifndef EPROTONOSUPPORT -#define EPROTONOSUPPORT 93 +#define EPROTONOSUPPORT 206 #endif -/** Operation not supported on transport endpoint */ +/** Operation not supported */ #ifndef ENOTSUP -#define ENOTSUP 95 +#define ENOTSUP 207 #endif /** Address family not supported by protocol */ #ifndef EAFNOSUPPORT -#define EAFNOSUPPORT 97 +#define EAFNOSUPPORT 208 #endif /** Cannot assign requested address */ #ifndef EADDRNOTAVAIL -#define EADDRNOTAVAIL 99 +#define EADDRNOTAVAIL 209 #endif /** Software caused connection abort */ #ifndef ECONNABORTED -#define ECONNABORTED 103 +#define ECONNABORTED 210 #endif /** Connection reset by peer */ #ifndef ECONNRESET -#define ECONNRESET 104 +#define ECONNRESET 211 #endif /** Transport endpoint is not connected */ #ifndef ENOTCONN -#define ENOTCONN 107 +#define ENOTCONN 212 #endif /** Connection timed out */ #ifndef ETIMEDOUT -#define ETIMEDOUT 110 +#define ETIMEDOUT 213 #endif /** Connection refused */ #ifndef ECONNREFUSED -#define ECONNREFUSED 111 +#define ECONNREFUSED 214 #endif /** Operation already in progress */ #ifndef EALREADY -#define EALREADY 114 +#define EALREADY 215 #endif /** Operation now in progress */ #ifndef EINPROGRESS -#define EINPROGRESS 115 +#define EINPROGRESS 216 #endif /** Authentication error */ #ifndef EAUTH -#define EAUTH 116 +#define EAUTH 217 #endif diff --git a/src/fmt/print.c b/src/fmt/print.c index 447d031..232a230 100644 --- a/src/fmt/print.c +++ b/src/fmt/print.c @@ -147,6 +147,7 @@ static size_t local_ftoa(char *buf, double n, size_t dp) * %J (struct sa *) Socket address and port - like 1.2.3.4:1234 * %H (re_printf_h *, void *) Print handler with argument * %v (char *fmt, va_list *) Variable argument list + * %m (int) Describe an error code * * * Reserved for the future: @@ -311,6 +312,14 @@ int re_vhprintf(const char *fmt, va_list ap, re_vprintf_h *vph, void *arg) fm = true; break; + case 'm': + (void)strerror_r(va_arg(ap, int), addr, sizeof(addr)); + addr[sizeof(addr)-1] = '\0'; + + err |= write_padded(addr, strlen(addr), pad, ' ', + plr, NULL, vph, arg); + break; + case 'p': ptr = va_arg(ap, void *);