Unify ERRMSG1 and ERRMSG2 to ERRMSG_FMT variadic macro

This commit is contained in:
Nobuyoshi Nakada 2024-04-07 15:28:07 +09:00
parent dfa0897de8
commit b5b54c19f6
No known key found for this signature in database
GPG Key ID: 3582D74E1FEE4465

View File

@ -3140,9 +3140,13 @@ f_exec(int c, const VALUE *a, VALUE _)
UNREACHABLE_RETURN(Qnil); UNREACHABLE_RETURN(Qnil);
} }
#define ERRMSG(str) do { if (errmsg && 0 < errmsg_buflen) strlcpy(errmsg, (str), errmsg_buflen); } while (0) #define ERRMSG(str) \
#define ERRMSG1(str, a) do { if (errmsg && 0 < errmsg_buflen) snprintf(errmsg, errmsg_buflen, (str), (a)); } while (0) ((errmsg && 0 < errmsg_buflen) ? \
#define ERRMSG2(str, a, b) do { if (errmsg && 0 < errmsg_buflen) snprintf(errmsg, errmsg_buflen, (str), (a), (b)); } while (0) (void)strlcpy(errmsg, (str), errmsg_buflen) : (void)0)
#define ERRMSG_FMT(...) \
((errmsg && 0 < errmsg_buflen) ? \
(void)snprintf(errmsg, errmsg_buflen, __VA_ARGS__) : (void)0)
static int fd_get_cloexec(int fd, char *errmsg, size_t errmsg_buflen); static int fd_get_cloexec(int fd, char *errmsg, size_t errmsg_buflen);
static int fd_set_cloexec(int fd, char *errmsg, size_t errmsg_buflen); static int fd_set_cloexec(int fd, char *errmsg, size_t errmsg_buflen);