Previous: Error Codes, Up: Error Handling


3.3.4 Error Strings

— Function: const char * gcry_strerror (gcry_error_t err)

The function gcry_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.

— Function: const char * gcry_strsource (gcry_error_t err)

The function gcry_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 the functions described above:

     {
       gcry_cipher_hd_t handle;
       gcry_error_t err = 0;
     
       err = gcry_cipher_open (&handle, GCRY_CIPHER_AES,
                               GCRY_CIPHER_MODE_CBC, 0);
       if (err)
         {
           fprintf (stderr, "Failure: %s/%s\n",
                    gcry_strsource (err),
                    gcry_strerror (err));
         }
     }