Registering messages
The error module can provide a system that extends the errno system of the C standard library. It consists in 2 parts:
So one has to first register all the error messages that a program or a library should manage. Then, when an error occurs, use eina_error_set(), and when errors are managed, use eina_error_get(). If eina_error_set() is used to set an error, do not forget to remove previous set errors before calling eina_error_set().
Here is an example for use:
#include <stdlib.h>
#include <stdio.h>
#include <eina_main.h>
#include <eina_error.h>
void *data_new()
{
return NULL;
}
int test(int n)
{
if (n < 0)
{
return 0;
}
return 1;
}
int main(void)
{
void *data;
{
printf ("Error during the initialization of eina_error module\n");
return EXIT_FAILURE;
}
data = data_new();
if (!data)
{
if (err)
printf("Error during memory allocation: %s\n",
}
if (!test(0))
{
if (err)
printf("Error during test function: %s\n",
}
if (!test(-1))
{
if (err)
printf("Error during test function: %s\n",
}
return EXIT_SUCCESS;
}
EINA_API Eina_Error eina_error_msg_static_register(const char *msg)
Registers a new error type, statically allocated message.
Definition: eina_error.c:251
EINA_API void eina_error_set(Eina_Error err)
Sets the last error.
Definition: eina_error.c:398
int Eina_Error
The integer type containing the error type.
Definition: eina_error.h:90
EINA_API const char * eina_error_msg_get(Eina_Error error)
Returns the description of the given error number.
Definition: eina_error.c:295
EINA_API Eina_Error eina_error_get(void)
Returns the last set error.
Definition: eina_error.c:389
EINA_API int eina_shutdown(void)
Shuts down the Eina library.
Definition: eina_main.c:379
EINA_API int eina_init(void)
Initializes the Eina library.
Definition: eina_main.c:291