From a981de9d6ae978e2031b531585c97ae73d270e66 Mon Sep 17 00:00:00 2001 From: Love Hornquist Astrand Date: Thu, 11 Mar 2010 23:35:00 -0800 Subject: [PATCH] move same ifdef magic from roken-common.h.in to here, use strerror() --- lib/roken/strerror_r.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/lib/roken/strerror_r.c b/lib/roken/strerror_r.c index 2acc8a8c0..05b07b53e 100644 --- a/lib/roken/strerror_r.c +++ b/lib/roken/strerror_r.c @@ -33,16 +33,37 @@ #include -#if !defined(HAVE_STRERROR_R) && !defined(STRERROR_R_PROTO_COMPATIBLE) +#if (!defined(HAVE_STRERROR_R) && !defined(strerror_r)) || (!defined(STRERROR_R_PROTO_COMPATIBLE) && defined(HAVE_STRERROR_R)) #include #include #include +<<<<<<< HEAD #ifndef HAVE_STRERROR_R extern int sys_nerr; extern char *sys_errlist[]; #endif +======= +#ifdef _MSC_VER + +int ROKEN_LIB_FUNCTION +rk_strerror_r(int eno, char * strerrbuf, size_t buflen) +{ + errno_t err; + + err = strerror_s(strerrbuf, buflen, eno); + if (err != 0) { + int code; + code = sprintf_s(strerrbuf, buflen, "Error % occurred.", eno); + err = ((code != 0)? errno : 0); + } + + return err; +} + +#else /* _MSC_VER */ +>>>>>>> 6da28e7... move same ifdef magic from roken-common.h.in to here, use strerror() int ROKEN_LIB_FUNCTION rk_strerror_r(int eno, char *strerrbuf, size_t buflen) @@ -57,11 +78,7 @@ rk_strerror_r(int eno, char *strerrbuf, size_t buflen) return 0; #else int ret; - if(eno < 0 || eno >= sys_nerr) { - snprintf(strerrbuf, buflen, "Error %d occurred.", eno); - return EINVAL; - } - ret = snprintf(strerrbuf, buflen, "%s", sys_errlist[eno]); + ret = strlcpy(strerrbuf, buflen, strerror(eno)); if (ret > buflen) return ERANGE; return 0; -- 2.11.4.GIT