Next: , Previous: Data Types, Up: Generalities


5.2 Initializing the library

In general the library requires no initialization. There are however some initialization hooks provided which are often useful. These should be called as early as possible and in a multi-threaded application before a second thread is created.

If your application uses its own memory allocation functions or wrappers it is good idea to tell libassuan about it so it can make use of the same functions or wrappers. You do this with

— Function: void assuan_set_malloc_hooks (void *(*malloc_func)(size_t), void *(*realloc_func)(void *, size_t), void (*free_func)(void*))

You need to provide all three functions. Those functions need to behave exactly as their standard counterparts (malloc, realloc and free). If you write your own functions please take care to set errno whenever an error has occurred.

To integrate assuan logging and diagnostics into your own logging system, you may use the following two functions:

— Function: void assuan_set_assuan_log_stream (FILE *fp)

This sets the stream to which libassuan should log messages not associated with a specific context to fp. The default is to log to stderr. This default value is also changed by using assuan_set_log_stream (to set a logging stream for a specific context) unless this function has been used. Obviously this is not thread-safe and thus it is highly recommended to use this function to setup a proper default.

— Function: void assuan_set_assuan_log_prefix (const char *text)

Set the prefix to be used at the start of a line emitted by assuan on the log stream to text. The default is the empty string.

If you intend to use libassuan along with the package libgpg-error it is recommended to switch libassuan into a mode which directly makes use of error codes provided by libgpg-error. Because the Assuan error codes and those of gpg-error overlap, it is required to explicitly request this. You do this by calling the function

— Function: void assuan_set_assuan_err_source (int errsource)

Enable gpg-error style error codes. errsource is one of the gpg-error sources. Switching back to the old style mode is not possible. The usual way to call this function is

          assuan_set_assuan_err_source (GPG_ERR_SOURCE_DEFAULT);