commit 4b5ee8bf10cb35d84d88688aa050dd8bee467da7 Author: starnakin Date: Tue Jun 27 21:08:13 2023 +0200 init diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3b4ff47 --- /dev/null +++ b/Makefile @@ -0,0 +1,28 @@ +CC = gcc +CFLAGS = -Wall -Wextra -Werror + +NAME = bozolib +SRC_DIR = src +OBJ_DIR = obj +SOURCES = $(shell find $(SRC_DIR) -type f -name '*.c') +OBJECTS = $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o,$(SOURCES)) +DEPS = $(OBJECTS:.o=.d) + +all: $(NAME) + +$(NAME): $(OBJECTS) + ar -rc $(NAME) $(OBJECTS) + +-include $(DEPS) + +$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c + @mkdir -p $(@D) + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -rf $(OBJ_DIR) + +fclean: clean + rm -f $(NAME) + +re: fclean $(NAME) diff --git a/src/lst/lst.h b/src/lst/lst.h new file mode 100644 index 0000000..f01108c --- /dev/null +++ b/src/lst/lst.h @@ -0,0 +1,14 @@ +#pragma once +#include + +typedef struct s_lst +{ + void* content; + struct s_lst* next; +} lst; + +size_t lst_len(const lst* root); +void lst_iter(const lst* root, void (*f)(void *)); +lst* lst_find(lst* root, void (*cmp)(const lst* lst1, const lst* lst2)); +void lst_addback(lst** root, lst* nouveau); +void lst_clear(lst** root, void (*del)(void *)); diff --git a/src/lst/lst_len.c b/src/lst/lst_len.c new file mode 100644 index 0000000..999a93f --- /dev/null +++ b/src/lst/lst_len.c @@ -0,0 +1,14 @@ +#include +#include "./lst.h" + +size_t lst_len(const lst* root) +{ + size_t i = 0; + const lst *current = root; + while (current != NULL) + { + current = current->next; + i++; + } + return i; +}