Previous: Error Codes, Up: Error Handling


5.4 Error Strings

— Function: const char * gpgme_strerror (gpgme_error_t err)

The function gpgme_strerror returns a pointer to a statically allocated string containing a description of the error code contained in the error value err. This string can be used to output a diagnostic message to the user.

This function is not thread safe. Use gpgme_strerror_r in multi-threaded programs.

— Function: int gpgme_strerror_r (gpgme_error_t err, char *buf, size_t buflen)

The function gpgme_strerror_r returns the error string for err in the user-supplied buffer buf of size buflen. This function is, in contrast to gpgme_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.

— Function: const char * gpgme_strsource (gpgme_error_t err)

The function gpgme_strerror returns a pointer to a statically allocated string containing a description of the error source contained in the error value err. This string can be used to output a diagnostic message to the user.

The following example illustrates the use of gpgme_strerror:

     gpgme_ctx_t ctx;
     gpgme_error_t err = gpgme_new (&ctx);
     if (err)
       {
         fprintf (stderr, "%s: creating GpgME context failed: %s: %s\n",
                  argv[0], gpgme_strsource (err), gpgme_strerror (err));
         exit (1);
       }