eina_error_01.c

- Main Page
- Related Pages
- Modules
- Data Structures
- Files
- Examples

eina_error_01.c

Of course, instead of printf(), eina_log_print() can be used to have beautiful error messages.

Of course, instead of printf(), eina_log_print() can be used to have beautiful error messages.

//Compile with:
//gcc -g eina_error_01.c -o eina_error_01 `pkg-config --cflags --libs eina`
#include <stdlib.h>
#include <stdio.h>
#include <eina_main.h>
#include <eina_error.h>
Eina_Error MY_ERROR_NEGATIVE;
Eina_Error MY_ERROR_NULL;
void *data_new()
{
eina_error_set(0);
eina_error_set(MY_ERROR_NULL);
return NULL;
}
int test(int n)
{
eina_error_set(0);
if (n < 0)
{
eina_error_set(MY_ERROR_NEGATIVE);
return 0;
}
return 1;
}
int main(void)
{
void *data;
if (!eina_init())
{
printf ("Error during the initialization of eina_error module\n");
return EXIT_FAILURE;
}
MY_ERROR_NEGATIVE = eina_error_msg_static_register("Negative number");
MY_ERROR_NULL = eina_error_msg_static_register("NULL pointer");
data = data_new();
if (!data)
{
Eina_Error err;
err = eina_error_get();
if (err)
printf("Error during memory allocation: %s\n",
eina_error_msg_get(err));
}
if (!test(0))
{
Eina_Error err;
err = eina_error_get();
if (err)
printf("Error during test function: %s\n",
eina_error_msg_get(err));
}
if (!test(-1))
{
Eina_Error err;
err = eina_error_get();
if (err)
printf("Error during test function: %s\n",
eina_error_msg_get(err));
}
eina_shutdown();
return EXIT_SUCCESS;
}
eina_error_msg_static_register
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_error_set
EINA_API void eina_error_set(Eina_Error err)
Sets the last error.
Definition: eina_error.c:398
Eina_Error
int Eina_Error
The integer type containing the error type.
Definition: eina_error.h:90
eina_error_msg_get
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_error_get
EINA_API Eina_Error eina_error_get(void)
Returns the last set error.
Definition: eina_error.c:389
eina_shutdown
EINA_API int eina_shutdown(void)
Shuts down the Eina library.
Definition: eina_main.c:379
eina_init
EINA_API int eina_init(void)
Initializes the Eina library.
Definition: eina_main.c:291