strerror_r returns trash when I manually set errno during testing
- by Robert S. Barnes
During testing I have a mock object which sets errno = ETIMEDOUT; The object I'm testing sees the error and calls strerror_r to get back an error string:
if (ret) {
if (ret == EAI_SYSTEM) {
char err[128];
strerror_r(errno, err, 128);
err_string.assign(err);
} else {
err_string.assign(gai_strerror(ret));
}
return ret;
}
I don't understand why strerror_r is returning trash. I even tried calling
strerror_r(ETIMEDOUT, err, 128)
directly and still got trash. I must be missing something. It seems I'm getting the gnu version of the function not the posix one, but that shouldn't make any difference in this case.