aboutsummaryrefslogtreecommitdiff
path: root/c-api/compat-5.3.c
diff options
context:
space:
mode:
authorPhilipp Janda <siffiejoe@gmx.net>2017-09-23 10:58:47 +0200
committerPhilipp Janda <siffiejoe@gmx.net>2017-09-23 10:58:47 +0200
commitb7829017581164c3e5dda24e3b187c0833b37dbf (patch)
treeaf55d098d680ae079c477acc6af27849e1046e15 /c-api/compat-5.3.c
parent9895acb9809cab5812277464a3c94a821d3c3af8 (diff)
downloadlua-compat-5.3-b7829017581164c3e5dda24e3b187c0833b37dbf.tar.gz
lua-compat-5.3-b7829017581164c3e5dda24e3b187c0833b37dbf.tar.bz2
lua-compat-5.3-b7829017581164c3e5dda24e3b187c0833b37dbf.zip
Do less stuff when sz is 0 in compat53_strerror().
Diffstat (limited to 'c-api/compat-5.3.c')
-rw-r--r--c-api/compat-5.3.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/c-api/compat-5.3.c b/c-api/compat-5.3.c
index eb62009..9b304c1 100644
--- a/c-api/compat-5.3.c
+++ b/c-api/compat-5.3.c
@@ -53,17 +53,17 @@
53static char* compat53_strerror (int en, char* buff, size_t sz) { 53static char* compat53_strerror (int en, char* buff, size_t sz) {
54#if COMPAT53_HAVE_STRERROR_R 54#if COMPAT53_HAVE_STRERROR_R
55 /* use strerror_r here, because it's available on these specific platforms */ 55 /* use strerror_r here, because it's available on these specific platforms */
56 if (sz > 0) 56 if (sz > 0) {
57 buff[0] = '\0'; 57 buff[0] = '\0';
58 /* we don't care whether the GNU version or the XSI version is used: */ 58 /* we don't care whether the GNU version or the XSI version is used: */
59 strerror_r(en, buff, sz); 59 strerror_r(en, buff, sz);
60 if (sz == 0 || buff[0] != '\0') 60 if (buff[0] == '\0')
61 return buff; /* strerror_r wrote into the buffer */ 61 /* buffer is unchanged, so we probably have called GNU strerror_r which
62 else 62 * returned a static constant string. Chances are that strerror will
63 /* buffer is unchanged, so we probably have called GNU strerror_r which 63 * return the same static constant string and therefore be thread-safe. */
64 * returned a static constant string. Chances are that strerror will 64 return strerror(en);
65 * return the same static constant string and therefore be thread-safe. */ 65 }
66 return strerror(en); 66 return buff; /* sz is 0 *or* strerror_r wrote into the buffer */
67#elif COMPAT53_HAVE_STRERROR_S 67#elif COMPAT53_HAVE_STRERROR_S
68 /* for MSVC and other C11 implementations, use strerror_s since it's 68 /* for MSVC and other C11 implementations, use strerror_s since it's
69 * provided by default by the libraries */ 69 * provided by default by the libraries */