Internal API
Macros
-
mylib_calloc(T, n)
Macro for allocating memory. This macro calls C standard library function
calloc()
and casts the returned pointer as a pointer to typeT
.- Parameters:
T – Type of the memory to be allocated.
n – Number of elements of type T to be allocated.
- Returns:
Pointer to the allocated memory.
-
mylib_realloc(T, ptr, n)
Macro for re-allocating memory. This macro calls C standard library function
realloc()
and casts the returned pointer as a pointer to typeT
.- Parameters:
T – Type of the memory to be allocated.
ptr – Pointer to already allocated memory.
n – Number of elements of type T to be allocated.
- Returns:
Pointer to the allocated memory.
-
mylib_free(p)
Macro for freeing memory. This macro calls mylib_free_() function.
- Parameters:
p – Pointer to the memory to be freed.
-
mylib_log(type, error_no, ...)
Wrapper macro around the mylib_log_() function.
- Parameters:
type – Log type.
error_no – Error number or id (e.g., MYLIB_INVALID_USER_INPUT).
... – printf() like format string for the log message and relevant arguments (if any).
-
mylib_info(...)
Convenient macro to log a general information.
- Parameters:
... – printf() like format string and arguments.
-
mylib_warn(cond, ...)
Convenient macro to log a warning if a condition is met.
- Parameters:
cond – Condition to trigger the warning.
... – printf() like format string and arguments.
-
mylib_error(cond, error_id, ...)
Convenient macro to log a error and return if a condition is met.
- Parameters:
cond – Condition to trigger the warning.
error_id – Error id for the error.
... – printf() like format string and arguments.
-
mylib_check(call)
Check the return value of an internal mylib call. Return the error id if it is not equal to MYLIB_SUCCESS. All mylib internal API functions return error ids generated by mylib_log() function.
- Parameters:
call – Return value from an internal mylib call.
-
mylib_check_ptr(ptr)
Check if the given pointer is NULL.
- Parameters:
ptr – Pointer to be checked.
-
mylib_check_ptr2(ptr)
Check if the dereferenced value of a pointer is NULL.
- Parameters:
ptr – Pointer to the pointer to be checked.
Functions
-
void mylib_free_(void **ptr)
Function for freeing memory. mylib_free_() calls C standard library function
free()
and sets the pointer to NULL.- Parameters:
ptr – Pointer to the memory address (pointer to a pointer) to be freed.
-
void mylib_log_init(const mylib_log_type_t type)
Set the priority level for logging. All the calls to mylib_log() using a log type with a higher priority than
type
will generate output on stderr.- Parameters:
type – Log type with the lowest priority which will generate output.
- Returns:
int
-
void mylib_log_set_type(const mylib_log_type_t type)
Set the priority level for logging. All the calls to mylib_log() using a log type with a higher priority than
type
will generate output on stderr.- Parameters:
type – Log type with the lowest priority which will generate output.
- Returns:
int
-
int mylib_log_(const mylib_log_type_t type, const int error_id, const char *fmt_, ...)
Output a message to the stderr if the log type
type
has a higher priority than the type set during mylib_log_init(). In addition, all the log messages which has a type of MYLIB_ERROR is stored so that they could be later queried by the user using the integer id returned by mylib_log_(). mylib_log_() returns 0 for all other log types and the respective message is not stored.Users must use mylib_log() macro instead of directly calling mylib_log_().
- Parameters:
type – Log type.
error_id – Error number or id (e.g., MYLIB_INVALID_USER_INPUT).
fmt_ – Format string for the log message.
... – printf() arguments: file name, line number and other optional arguments if any.
- Returns:
int
-
int mylib_get_error_id(int *error_id, const int index)
Get the error id given the error index returned by a mylib API call.
- Parameters:
error_id – Error id corresponding to the index
index
.index – Error index returned by a mylib API call.
- Returns:
int
-
int mylib_get_error_message(char **error_msg, const int index)
Get the error message given the error index returned by a mylib API call.
- Parameters:
error_msg – Error message corresponding to the index
index
.index – Error index returned by a mylib API call.
- Returns:
int
-
int mylib_log_finalize(void)
Release the memory allocated for the stored error messages and reset the log type used as the priority.
- Returns:
int
Structures
-
struct mylib
mylib handle returned by mylib_init().
Public Members
-
unsigned verbose
Verbosity level.
-
unsigned verbose