libds/include/libds.h

42 lines
1.2 KiB
C
Raw Normal View History

#ifndef LIBDS_HEADER
#define LIBDS_HEADER
#include <stdarg.h>
/**
* Enum representing return codes from error-prone libds functions.
*/
enum libds_result_e { LIBDS_SUCCESS, LIBDS_MALLOC };
typedef enum libds_result_e libds_result;
/**
* Comparison function type.
* Comparison functions are used in searches etc.
* The function should take two elements, and, if they match, return 1. Otherwise, it should
* return 0.
*/
typedef int (*compare_func)(void*, void*);
/**
* Foreach function type.
* Foreach functions are passed to _foreach calls.
* The function should return 0 if all goes well, or a nonzero error code if there is an issue.
*/
typedef int (*foreach_func)(void*, va_list);
/**
* A compare_func implementation that always returns true.
* @param a The first piece of data being compared
* @param b The second piece of data being compared
* @return always true, i.e 1
*/
int compare_always(void* a, void* b);
/**
* A compare_func implementation that compares two pointers using ==.
* @param a the first piece of data being compared
* @param b the second piece of data being compared
* @return true if a and b are the same value.
*/
int compare_pointer(void* a, void* b);
#endif