POSIX allows successful system calls to modify errno, so always clear the error_code if the result indicates success.