Use strerror_r over strerror for thread safety

strerror is not reentrant and not guaranteed to be thread safe, so we
should use strerror_r instead.