MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / compat53_strerror

Function compat53_strerror

extlibs/sol3/include/sol/sol.hpp:2456–2488  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2454#endif /* Lua File Buffer Size */
2455
2456static char* compat53_strerror(int en, char* buff, size_t sz) {
2457#if COMPAT53_HAVE_STRERROR_R
2458 /* use strerror_r here, because it's available on these specific platforms */
2459 if (sz > 0) {
2460 buff[0] = '\0';
2461 /* we don't care whether the GNU version or the XSI version is used: */
2462 if (strerror_r(en, buff, sz)) {
2463 /* Yes, we really DO want to ignore the return value!
2464 * GCC makes that extra hard, not even a (void) cast will do. */
2465 }
2466 if (buff[0] == '\0') {
2467 /* Buffer is unchanged, so we probably have called GNU strerror_r which
2468 * returned a static constant string. Chances are that strerror will
2469 * return the same static constant string and therefore be thread-safe. */
2470 return strerror(en);
2471 }
2472 }
2473 return buff; /* sz is 0 *or* strerror_r wrote into the buffer */
2474#elif COMPAT53_HAVE_STRERROR_S
2475 /* for MSVC and other C11 implementations, use strerror_s since it's
2476 * provided by default by the libraries */
2477 strerror_s(buff, sz, en);
2478 return buff;
2479#else
2480 /* fallback, but strerror is not guaranteed to be threadsafe due to modifying
2481 * errno itself and some impls not locking a static buffer for it ... but most
2482 * known systems have threadsafe errno: this might only change if the locale
2483 * is changed out from under someone while this function is being called */
2484 (void)buff;
2485 (void)sz;
2486 return strerror(en);
2487#endif
2488}
2489
2490COMPAT53_API int lua_absindex(lua_State *L, int i) {
2491 if (i < 0 && i > LUA_REGISTRYINDEX)

Callers 2

luaL_fileresultFunction · 0.85
compat53_errfileFunction · 0.85

Calls 2

strerror_rFunction · 0.85
strerror_sFunction · 0.85

Tested by

no test coverage detected