list/list.h

47 lines
1.4 KiB
C
Raw Normal View History

2024-12-25 08:16:16 +00:00
#ifndef LIST_H
#define LIST_H
#ifdef __cplusplus
extern "C"
{
#endif // __cplusplus
typedef struct list_node_t
{
void *data;
struct list_node_t *next;
} list_node_t;
typedef list_node_t *list_t;
typedef enum list_error
{
LIST_OK = 0,
LIST_ERR_LIST_IS_NULL = 1,
LIST_ERR_MALLOC_FAILED,
} list_error;
/**
* @brief list为NULL
* @param list
* @param data
*/
int list_node_add(list_t *list, void *data);
/**
* @brief
* @param list
* @param data
*/
int list_node_remove(list_t *list, void *data);
int list_size(list_t *list);
/**
* @param list
* @param data
* @warning
*/
#define EXPORT_LIST_NODE(list, data) \
int __attribute__((constructor)) export_list_node_##list_##data(void) \
{ \
return list_node_add(&list, (void *)&data); \
}
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // LIST_H