replace strerror() to strerror_r() for thread safety