示例#1
0
char* strerror(int error_number) {
  // Just return the original constant in the easy cases.
  char* result = const_cast<char*>(__strerror_lookup(error_number));
  if (result != nullptr) {
    return result;
  }

  result = g_strerror_tls_buffer.get();
  strerror_r(error_number, result, g_strerror_tls_buffer.size());
  return result;
}
示例#2
0
int strerror_r(int error_number, char* buf, size_t buf_len) {
  ErrnoRestorer errno_restorer;
  size_t length;

  const char* error_name = __strerror_lookup(error_number);
  if (error_name != NULL) {
    length = strlcpy(buf, error_name, buf_len);
  } else {
    length = __libc_format_buffer(buf, buf_len, "Unknown error %d", error_number);
  }
  if (length >= buf_len) {
    errno_restorer.override(ERANGE);
    return -1;
  }
示例#3
0
int strerror_r(int error_number, char* buf, size_t buf_len) {
  int saved_errno = errno;
  size_t length;

  const char* error_name = __strerror_lookup(error_number);
  if (error_name != NULL) {
    length = snprintf(buf, buf_len, "%s", error_name);
  } else {
    length = snprintf(buf, buf_len, "Unknown error %d", error_number);
  }
  if (length >= buf_len) {
    errno = ERANGE;
    return -1;
  }

  errno = saved_errno;
  return 0;
}