static int gpgme_error_to_errno (gpgme_error_t err) { int no = gpg_err_code_to_errno (err); if (no) { errno = no; return -1; } switch (gpg_err_code (err)) { case GPG_ERR_EOF: return 0; case GPG_ERR_INV_VALUE: errno = EINVAL; return -1; case GPG_ERR_NOT_SUPPORTED: errno = ENOSYS; return -1; default: /* FIXME: Yeah, well. */ errno = EINVAL; return -1; } }
static int gpgme_error_to_errno (gpgme_error_t err) { int res = gpg_err_code_to_errno (err); if (!err) { switch (gpg_err_code (err)) { case GPG_ERR_EOF: res = 0; break; case GPG_ERR_INV_VALUE: res = EINVAL; break; case GPG_ERR_NOT_SUPPORTED: res = ENOSYS; break; default: /* FIXME: Yeah, well. */ res = EINVAL; break; } } TRACE3 (DEBUG_DATA, "gpgme:gpgme_error_to_errno", 0, "mapping %s <%s> to: %s", gpgme_strerror (err), gpgme_strsource (err), strerror (res)); errno = res; return res ? -1 : 0; }
/* Return the error string for ERR in the user-supplied buffer BUF of size BUFLEN. This function is, in contrast to gpg_strerror, thread-safe if a thread-safe strerror_r() function is provided by the system. If the function succeeds, 0 is returned and BUF contains the string describing the error. If the buffer was not large enough, ERANGE is returned and BUF contains as much of the beginning of the error string as fits into the buffer. */ int gpg_strerror_r (gpg_error_t err, char *buf, size_t buflen) { gpg_err_code_t code = gpg_err_code (err); const char *errstr; size_t errstr_len; size_t cpy_len; if (code & GPG_ERR_SYSTEM_ERROR) { int no = gpg_err_code_to_errno (code); if (no) { int system_err = system_strerror_r (no, buf, buflen); if (system_err != EINVAL) { if (buflen) buf[buflen - 1] = '\0'; return system_err; } } code = GPG_ERR_UNKNOWN_ERRNO; } errstr = dgettext (PACKAGE, msgstr + msgidx[msgidxof (code)]); errstr_len = strlen (errstr) + 1; cpy_len = errstr_len < buflen ? errstr_len : buflen; memcpy (buf, errstr, cpy_len); if (buflen) buf[buflen - 1] = '\0'; return cpy_len == errstr_len ? 0 : ERANGE; }
/* Return a pointer to a string containing a description of the error code in the error value ERR. This function is not thread-safe. */ const char * gpg_strerror (gpg_error_t err) { gpg_err_code_t code = gpg_err_code (err); if (code & GPG_ERR_SYSTEM_ERROR) { int no = gpg_err_code_to_errno (code); if (no) return strerror (no); else code = GPG_ERR_UNKNOWN_ERRNO; } return dgettext (PACKAGE, msgstr + msgidx[msgidxof (code)]); }