提交 eca5c0ad authored 作者: Stefan Knoblich's avatar Stefan Knoblich

FreeSWITCH: Add WIN32 strerror_s() variant to custom switch_strerror_r() helper…

FreeSWITCH: Add WIN32 strerror_s() variant to custom switch_strerror_r() helper function and fix more strerror_r() users.

Convert mod_xml_cdr, mod_json_cdr and mod_conference to the new function.
Signed-off-by: 's avatarStefan Knoblich <stkn@openisdn.net>
上级 8bcf3b4f
...@@ -1029,12 +1029,8 @@ static void conference_cdr_render(conference_obj_t *conference) ...@@ -1029,12 +1029,8 @@ static void conference_cdr_render(conference_obj_t *conference)
fd = -1; fd = -1;
} else { } else {
char ebuf[512] = { 0 }; char ebuf[512] = { 0 };
#ifdef WIN32 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error writing [%s][%s]\n",
strerror_s(ebuf, sizeof(ebuf), errno); path, switch_strerror_r(errno, ebuf, sizeof(ebuf)));
#else
strerror_r(errno, ebuf, sizeof(ebuf));
#endif
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error writing [%s][%s]\n", path, ebuf);
} }
......
...@@ -253,12 +253,8 @@ static switch_status_t my_on_reporting(switch_core_session_t *session) ...@@ -253,12 +253,8 @@ static switch_status_t my_on_reporting(switch_core_session_t *session)
} }
} else { } else {
char ebuf[512] = { 0 }; char ebuf[512] = { 0 };
#ifdef WIN32 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error writing [%s][%s]\n",
strerror_s(ebuf, sizeof(ebuf), errno); path, switch_strerror_r(errno, ebuf, sizeof(ebuf)));
#else
strerror_r(errno, ebuf, sizeof(ebuf));
#endif
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error writing [%s][%s]\n", path, ebuf);
} }
switch_safe_free(path); switch_safe_free(path);
} }
...@@ -412,12 +408,8 @@ static switch_status_t my_on_reporting(switch_core_session_t *session) ...@@ -412,12 +408,8 @@ static switch_status_t my_on_reporting(switch_core_session_t *session)
break; break;
} else { } else {
char ebuf[512] = { 0 }; char ebuf[512] = { 0 };
#ifdef WIN32 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open %s! [%s]\n",
strerror_s(ebuf, sizeof(ebuf), errno); path, switch_strerror_r(errno, ebuf, sizeof(ebuf)));
#else
strerror_r(errno, ebuf, sizeof(ebuf));
#endif
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open %s! [%s]\n", path, ebuf);
} }
......
...@@ -244,12 +244,8 @@ static switch_status_t my_on_reporting(switch_core_session_t *session) ...@@ -244,12 +244,8 @@ static switch_status_t my_on_reporting(switch_core_session_t *session)
fd = -1; fd = -1;
} else { } else {
char ebuf[512] = { 0 }; char ebuf[512] = { 0 };
#ifdef WIN32 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error writing [%s][%s]\n",
strerror_s(ebuf, sizeof(ebuf), errno); path, switch_strerror_r(errno, ebuf, sizeof(ebuf)));
#else
strerror_r(errno, ebuf, sizeof(ebuf));
#endif
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error writing [%s][%s]\n", path, ebuf);
} }
switch_safe_free(path); switch_safe_free(path);
} }
...@@ -400,12 +396,8 @@ static switch_status_t my_on_reporting(switch_core_session_t *session) ...@@ -400,12 +396,8 @@ static switch_status_t my_on_reporting(switch_core_session_t *session)
fd = -1; fd = -1;
} else { } else {
char ebuf[512] = { 0 }; char ebuf[512] = { 0 };
#ifdef WIN32 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error![%s]\n",
strerror_s(ebuf, sizeof(ebuf), errno); switch_strerror_r(errno, ebuf, sizeof(ebuf)));
#else
strerror_r(errno, ebuf, sizeof(ebuf));
#endif
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error![%s]\n", ebuf);
} }
} }
} }
......
...@@ -2985,6 +2985,12 @@ SWITCH_DECLARE(char *) switch_strerror_r(int errnum, char *buf, switch_size_t bu ...@@ -2985,6 +2985,12 @@ SWITCH_DECLARE(char *) switch_strerror_r(int errnum, char *buf, switch_size_t bu
} }
return buf; return buf;
#endif /* STRERROR_R_CHAR_P */ #endif /* STRERROR_R_CHAR_P */
#elif defined(WIN32)
/* WIN32 variant */
if (strerror_s(buf, buflen, errnum)) {
switch_snprintf(buf, buflen, "Unknown error %d", errnum);
}
return buf;
#else #else
/* Fallback, copy string into private buffer */ /* Fallback, copy string into private buffer */
switch_copy_string(buf, strerror(errnum), buflen); switch_copy_string(buf, strerror(errnum), buflen);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论