From 8680737a802539f3c21a295ad45eb9be72c73f5f Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Sat, 1 Aug 2020 21:25:09 +0200 Subject: More UNIX friendly libft --- libft/Makefile | 15 +++- libft/inc/libft.h | 224 -------------------------------------------------- libft/include/libft.h | 224 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 236 insertions(+), 227 deletions(-) delete mode 100644 libft/inc/libft.h create mode 100644 libft/include/libft.h (limited to 'libft') diff --git a/libft/Makefile b/libft/Makefile index 6803f66..ac06d94 100644 --- a/libft/Makefile +++ b/libft/Makefile @@ -3,10 +3,11 @@ default: all #--------------------------------- Shell --------------------------------------# #==============================================================================# SHELL := /bin/sh +OS = $(shell uname) #==============================================================================# #------------------------------ Directories -----------------------------------# #==============================================================================# -INCS_DIR = inc/ +INCS_DIR = include/ SRCS_DIR = src/ OBJS_DIR = obj/ #==============================================================================# @@ -120,9 +121,17 @@ OS = $(shell uname) #==============================================================================# #-------------------------------- Compiler ------------------------------------# #==============================================================================# -CC = clang +ifeq (${OS}, FreeBSD) +CC = /usr/bin/cc +endif +ifeq (${OS}, Linux) +CC = /usr/bin/clang-9 +endif +ifeq (${OS}, Darwin) +CC = clang +endif #------------------------------------------------------------------------------# -CFLAGS = -std=c89 +CFLAGS = -std=c89 CFLAGS += -Wall CFLAGS += -Wextra CFLAGS += -Werror diff --git a/libft/inc/libft.h b/libft/inc/libft.h deleted file mode 100644 index 5ddb471..0000000 --- a/libft/inc/libft.h +++ /dev/null @@ -1,224 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* libft.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: rbousset +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ -/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ -/* */ -/* ************************************************************************** */ - -# ifndef LIBFT_H -# define LIBFT_H - -#include -#include -#include - -# define FT_MIN_HEX_BASE "0123456789abcdef" -# define FT_MAJ_HEX_BASE "0123456789ABCDEF" -# define FT_PRINTF_CONV_CHARSET "cspdiuxX%" -# ifndef BUFFER_SIZE -# define BUFFER_SIZE 72 -# endif - -typedef struct s_list -{ - void *content; - struct s_list *next; -} t_list; - -typedef struct s_gnl -{ - int fd; - char *rest; - struct s_gnl *next; -} t_gnl; - -typedef struct s_printflist -{ - int putlen; - char conv; - char actconv; - char *fullflag; - size_t flaglen; - int width; - int precision; - uint8_t isreverse; - uint8_t isneg; - uint8_t isaz; - int8_t isaspace; - uint8_t isaplus; - int8_t lh; - uint8_t zflag; - uint8_t issharp; - uint8_t isminus; - int fulllen; - char *output; -} t_printflist; - -/* -** VOID -*/ - -void ft_bzero(void *s, size_t n); -void ft_putendl_fd(char *s, int fd); -void ft_putnbr_fd(int n, int fd); -void ft_lstadd_front(t_list **alst, t_list *new); -void ft_lstadd_back(t_list **alst, t_list *new); -void ft_lstdelone(t_list *lst, void (*del)(void *)); -void ft_lstclear(t_list **lst, void (*del)(void *)); -void ft_lstiter(t_list *lst, void (*f)(void *)); -void ft_kernel_panic(void); -void ft_putnbr(long nb); -void ft_putnbr_base(long nb, char *base); -void ft_memdel(void **ptr); -void ft_delwords(char **words); -void *ft_memset(void *b, int c, size_t len); -void *ft_memcpy(void *dst, const void *src, size_t n); -void *ft_memccpy(void *dst, const void *src, - int c, size_t n); -void *ft_memmove(void *dst, const void *src, size_t len); -void *ft_memchr(const void *s, int c, size_t n); -void *ft_calloc(size_t count, size_t size); -void *ft_nrealloc(void *ptr, size_t oldsize, size_t newsize); - -/* -** CHAR -*/ - -char *ft_strcat(char *s1, const char *s2); -char *ft_strchr(const char *s, int c); -char *ft_strrchr(const char *s, int c); -char *ft_strnstr(const char *haystack, const char *needle, - size_t len); -char *ft_strdup(const char *s1); -char *ft_substr(const char *s, unsigned int start, - size_t len); -char *ft_strjoin(const char *s1, const char *s2); -char *ft_strtrim(const char *s1, const char *set); -char *ft_itoa(long n); -char *ft_itoa_base(long n, char *base); -char *ft_uitoa(unsigned long n); -char *ft_uitoa_base(unsigned long n, char *base); -char *ft_strmapi(const char *s, - char (*f)(unsigned int, char)); -char *ft_nstr(size_t size); -char *ft_strsubst(char *str, - const char *pattern, - const char *subst); -char **ft_split(const char *s, char c); - -/* -** INT -*/ - -uint8_t ft_isspace(int c); -uint8_t ft_ischarset(const char *charset, int c); -uint8_t ft_intlen(long n); -uint8_t ft_intlen_base(long n, char *base); -uint8_t ft_uintlen(unsigned long n); -uint8_t ft_uintlen_base(unsigned long n, char *base); -int ft_memcmp(const void *s1, const void *s2, size_t n); -int ft_isalpha(int c); -int ft_isdigit(int c); -int ft_isalnum(int c); -int ft_isascii(int c); -int ft_isprint(int c); -int ft_toupper(int c); -int ft_tolower(int c); -int ft_strncmp(const char *s1, const char *s2, size_t n); -int ft_lstsize(t_list *lst); -int ft_atoi(const char *str); -int ft_putchar(int c); -int ft_putnchar(int c, const size_t n); -int ft_putstr(const char *s); -int ft_putendl(const char *s); -int ft_putchar_fd(char c, int fd); -int ft_putstr_fd(char *s, int fd); -int ft_strcmp(const char *s1, const char *s2); -long ft_memlchr(const void *s, int c, size_t n); -long ft_strlchr(const char *s, int c); -size_t ft_strlen(const char *s); -size_t ft_strlcpy(char *dst, const char *src, size_t size); -size_t ft_strlcat(char *dst, const char *src, size_t size); -size_t ft_strnlen(const char *s, size_t size); -double ft_sqrt(double x); - -/* -** LIST -*/ - -t_list *ft_lstnew(void *content); -t_list *ft_lstlast(t_list *lst); -t_list *ft_lstmap(t_list *lst, void *(*f)(void *), - void (*del)(void *)); -/* -** get_next_line -*/ - -char *ft_strchr_gnl(const char *s, int c); -char *ft_swap_gnl(char *s1, char *free_ft); -int get_next_line(int fd, char **line); -int ft_free_gnl(int fd, t_gnl **list); -size_t ft_strlen_gnl(const char *s, char c); -t_gnl *ft_find_fd(int fd, t_gnl **list); - -/* -** ft_printf -*/ - -void ft_printf_process(const char *format, - va_list arg, - t_printflist *pflist); -void ft_printf_reinit_struct(t_printflist *pflist); -void ft_printf_cat_output(char *src, - size_t len, - t_printflist *format); -void ft_printf_treat_flags(va_list arg, - t_printflist *pflist); -void ft_printf_put_c(va_list arg, t_printflist *pflist); -void ft_printf_put_s(va_list arg, t_printflist *pflist); -void ft_printf_put_p(va_list arg, t_printflist *pflist); -void ft_printf_put_d(va_list arg, t_printflist *pflist); -void ft_printf_put_u(va_list arg, t_printflist *pflist); -void ft_printf_put_x(va_list arg, t_printflist *pflist); -void ft_printf_put_big_x(va_list arg, t_printflist *pflist); -void ft_printf_put_perc(va_list arg, t_printflist *pflist); -void ft_printf_put_none(t_printflist *pflist); -void ft_printf_put_width_pre(t_printflist *pflist); -void ft_printf_put_width_post(t_printflist *pflist); -char *ft_printf_get_flags(const char *format, - int pos, - t_printflist *pflist); -char *ft_printf_flag_to_atoi(char *str); -char *ft_printf_get_width_nstr(char *str, - t_printflist *pflist); -uint8_t ft_printf_is_multiwrite(const char *format); -int ft_printf_flags(const char *format, - int pos, - va_list arg, - t_printflist *pflist); -int ft_printf(const char *format, - ...) __attribute__((format(printf,1,2))); -int ft_dprintf(int fd, - const char *format, - ...) __attribute__((format(printf,2,3))); -int ft_sprintf(char *str, - const char *format, - ...) __attribute__((format(printf,2,3))); -int ft_printf_get_partlen(const char *format); -int ft_printf_putpart(const char *format, - int start, - int len, - t_printflist *pflist); -int ft_printf_put_precision(t_printflist *pflist); -int ft_printf_get_s_putlen(char *str, t_printflist *pflist); -int ft_printf_fetch_width(va_list arg, - char *nstr, - t_printflist *pflist); -t_printflist *ft_printf_init_struct(const char *format); - -# endif diff --git a/libft/include/libft.h b/libft/include/libft.h new file mode 100644 index 0000000..5ddb471 --- /dev/null +++ b/libft/include/libft.h @@ -0,0 +1,224 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* libft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +# ifndef LIBFT_H +# define LIBFT_H + +#include +#include +#include + +# define FT_MIN_HEX_BASE "0123456789abcdef" +# define FT_MAJ_HEX_BASE "0123456789ABCDEF" +# define FT_PRINTF_CONV_CHARSET "cspdiuxX%" +# ifndef BUFFER_SIZE +# define BUFFER_SIZE 72 +# endif + +typedef struct s_list +{ + void *content; + struct s_list *next; +} t_list; + +typedef struct s_gnl +{ + int fd; + char *rest; + struct s_gnl *next; +} t_gnl; + +typedef struct s_printflist +{ + int putlen; + char conv; + char actconv; + char *fullflag; + size_t flaglen; + int width; + int precision; + uint8_t isreverse; + uint8_t isneg; + uint8_t isaz; + int8_t isaspace; + uint8_t isaplus; + int8_t lh; + uint8_t zflag; + uint8_t issharp; + uint8_t isminus; + int fulllen; + char *output; +} t_printflist; + +/* +** VOID +*/ + +void ft_bzero(void *s, size_t n); +void ft_putendl_fd(char *s, int fd); +void ft_putnbr_fd(int n, int fd); +void ft_lstadd_front(t_list **alst, t_list *new); +void ft_lstadd_back(t_list **alst, t_list *new); +void ft_lstdelone(t_list *lst, void (*del)(void *)); +void ft_lstclear(t_list **lst, void (*del)(void *)); +void ft_lstiter(t_list *lst, void (*f)(void *)); +void ft_kernel_panic(void); +void ft_putnbr(long nb); +void ft_putnbr_base(long nb, char *base); +void ft_memdel(void **ptr); +void ft_delwords(char **words); +void *ft_memset(void *b, int c, size_t len); +void *ft_memcpy(void *dst, const void *src, size_t n); +void *ft_memccpy(void *dst, const void *src, + int c, size_t n); +void *ft_memmove(void *dst, const void *src, size_t len); +void *ft_memchr(const void *s, int c, size_t n); +void *ft_calloc(size_t count, size_t size); +void *ft_nrealloc(void *ptr, size_t oldsize, size_t newsize); + +/* +** CHAR +*/ + +char *ft_strcat(char *s1, const char *s2); +char *ft_strchr(const char *s, int c); +char *ft_strrchr(const char *s, int c); +char *ft_strnstr(const char *haystack, const char *needle, + size_t len); +char *ft_strdup(const char *s1); +char *ft_substr(const char *s, unsigned int start, + size_t len); +char *ft_strjoin(const char *s1, const char *s2); +char *ft_strtrim(const char *s1, const char *set); +char *ft_itoa(long n); +char *ft_itoa_base(long n, char *base); +char *ft_uitoa(unsigned long n); +char *ft_uitoa_base(unsigned long n, char *base); +char *ft_strmapi(const char *s, + char (*f)(unsigned int, char)); +char *ft_nstr(size_t size); +char *ft_strsubst(char *str, + const char *pattern, + const char *subst); +char **ft_split(const char *s, char c); + +/* +** INT +*/ + +uint8_t ft_isspace(int c); +uint8_t ft_ischarset(const char *charset, int c); +uint8_t ft_intlen(long n); +uint8_t ft_intlen_base(long n, char *base); +uint8_t ft_uintlen(unsigned long n); +uint8_t ft_uintlen_base(unsigned long n, char *base); +int ft_memcmp(const void *s1, const void *s2, size_t n); +int ft_isalpha(int c); +int ft_isdigit(int c); +int ft_isalnum(int c); +int ft_isascii(int c); +int ft_isprint(int c); +int ft_toupper(int c); +int ft_tolower(int c); +int ft_strncmp(const char *s1, const char *s2, size_t n); +int ft_lstsize(t_list *lst); +int ft_atoi(const char *str); +int ft_putchar(int c); +int ft_putnchar(int c, const size_t n); +int ft_putstr(const char *s); +int ft_putendl(const char *s); +int ft_putchar_fd(char c, int fd); +int ft_putstr_fd(char *s, int fd); +int ft_strcmp(const char *s1, const char *s2); +long ft_memlchr(const void *s, int c, size_t n); +long ft_strlchr(const char *s, int c); +size_t ft_strlen(const char *s); +size_t ft_strlcpy(char *dst, const char *src, size_t size); +size_t ft_strlcat(char *dst, const char *src, size_t size); +size_t ft_strnlen(const char *s, size_t size); +double ft_sqrt(double x); + +/* +** LIST +*/ + +t_list *ft_lstnew(void *content); +t_list *ft_lstlast(t_list *lst); +t_list *ft_lstmap(t_list *lst, void *(*f)(void *), + void (*del)(void *)); +/* +** get_next_line +*/ + +char *ft_strchr_gnl(const char *s, int c); +char *ft_swap_gnl(char *s1, char *free_ft); +int get_next_line(int fd, char **line); +int ft_free_gnl(int fd, t_gnl **list); +size_t ft_strlen_gnl(const char *s, char c); +t_gnl *ft_find_fd(int fd, t_gnl **list); + +/* +** ft_printf +*/ + +void ft_printf_process(const char *format, + va_list arg, + t_printflist *pflist); +void ft_printf_reinit_struct(t_printflist *pflist); +void ft_printf_cat_output(char *src, + size_t len, + t_printflist *format); +void ft_printf_treat_flags(va_list arg, + t_printflist *pflist); +void ft_printf_put_c(va_list arg, t_printflist *pflist); +void ft_printf_put_s(va_list arg, t_printflist *pflist); +void ft_printf_put_p(va_list arg, t_printflist *pflist); +void ft_printf_put_d(va_list arg, t_printflist *pflist); +void ft_printf_put_u(va_list arg, t_printflist *pflist); +void ft_printf_put_x(va_list arg, t_printflist *pflist); +void ft_printf_put_big_x(va_list arg, t_printflist *pflist); +void ft_printf_put_perc(va_list arg, t_printflist *pflist); +void ft_printf_put_none(t_printflist *pflist); +void ft_printf_put_width_pre(t_printflist *pflist); +void ft_printf_put_width_post(t_printflist *pflist); +char *ft_printf_get_flags(const char *format, + int pos, + t_printflist *pflist); +char *ft_printf_flag_to_atoi(char *str); +char *ft_printf_get_width_nstr(char *str, + t_printflist *pflist); +uint8_t ft_printf_is_multiwrite(const char *format); +int ft_printf_flags(const char *format, + int pos, + va_list arg, + t_printflist *pflist); +int ft_printf(const char *format, + ...) __attribute__((format(printf,1,2))); +int ft_dprintf(int fd, + const char *format, + ...) __attribute__((format(printf,2,3))); +int ft_sprintf(char *str, + const char *format, + ...) __attribute__((format(printf,2,3))); +int ft_printf_get_partlen(const char *format); +int ft_printf_putpart(const char *format, + int start, + int len, + t_printflist *pflist); +int ft_printf_put_precision(t_printflist *pflist); +int ft_printf_get_s_putlen(char *str, t_printflist *pflist); +int ft_printf_fetch_width(va_list arg, + char *nstr, + t_printflist *pflist); +t_printflist *ft_printf_init_struct(const char *format); + +# endif -- cgit v1.2.3