├── ft_putchar_fd.c ├── ft_isascii.c ├── ft_isdigit.c ├── ft_isprint.c ├── ft_tolower.c ├── ft_toupper.c ├── ft_isalpha.c ├── ft_putendl_fd.c ├── ft_strlen.c ├── ft_isalnum.c ├── ft_lstadd_front_bonus.c ├── ft_lstdelone_bonus.c ├── ft_lstlast_bonus.c ├── ft_strchr.c ├── ft_bzero.c ├── ft_lstadd_back_bonus.c ├── ft_putstr_fd.c ├── ft_memset.c ├── ft_calloc.c ├── ft_lstsize_bonus.c ├── ft_striteri.c ├── ft_strrchr.c ├── ft_lstclear_bonus.c ├── ft_lstiter_bonus.c ├── ft_lstnew_bonus.c ├── ft_memchr.c ├── ft_strdup.c ├── ft_strlcpy.c ├── ft_putnbr_fd.c ├── ft_strncmp.c ├── ft_memcpy.c ├── ft_memcmp.c ├── ft_strmapi.c ├── ft_lstmap_bonus.c ├── ft_strlcat.c ├── ft_substr.c ├── ft_atoi.c ├── ft_strjoin.c ├── ft_memmove.c ├── ft_strnstr.c ├── .gitignore ├── ft_strtrim.c ├── ft_itoa.c ├── Makefile ├── ft_split.c ├── libft.h ├── README.md └── LICENSE /ft_putchar_fd.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | void ft_putchar_fd(char c, int fd) 4 | { 5 | write(fd, &c, 1); 6 | } 7 | -------------------------------------------------------------------------------- /ft_isascii.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | int ft_isascii(int c) 4 | { 5 | if (c >= 0 && c <= 127) 6 | return (1); 7 | return (0); 8 | } 9 | -------------------------------------------------------------------------------- /ft_isdigit.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | int ft_isdigit(int c) 4 | { 5 | if (c >= 48 && c <= 57) 6 | return (1); 7 | return (0); 8 | } 9 | -------------------------------------------------------------------------------- /ft_isprint.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | int ft_isprint(int c) 4 | { 5 | if (c >= 32 && c <= 126) 6 | return (1); 7 | return (0); 8 | } 9 | -------------------------------------------------------------------------------- /ft_tolower.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | int ft_tolower(int c) 4 | { 5 | if (c >= 65 && c <= 90) 6 | c += 32; 7 | return (c); 8 | } 9 | -------------------------------------------------------------------------------- /ft_toupper.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | int ft_toupper(int c) 4 | { 5 | if (c >= 97 && c <= 122) 6 | c -= 32; 7 | return (c); 8 | } 9 | -------------------------------------------------------------------------------- /ft_isalpha.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | int ft_isalpha(int c) 4 | { 5 | if ((c >= 65 && c <= 90) || (c >= 97 && c <= 122)) 6 | return (1); 7 | return (0); 8 | } 9 | -------------------------------------------------------------------------------- /ft_putendl_fd.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | void ft_putendl_fd(char *s, int fd) 4 | { 5 | if (!s) 6 | return ; 7 | ft_putstr_fd(s, fd); 8 | write(fd, "\n", 1); 9 | } 10 | -------------------------------------------------------------------------------- /ft_strlen.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | size_t ft_strlen(const char *str) 4 | { 5 | int i; 6 | 7 | i = 0; 8 | while (str[i] != '\0') 9 | i++; 10 | return (i); 11 | } 12 | -------------------------------------------------------------------------------- /ft_isalnum.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | int ft_isalnum(int c) 4 | { 5 | if ((c >= 48 && c <= 57) || (c >= 65 && c <= 90) || (c >= 97 && c <= 122)) 6 | return (1); 7 | return (0); 8 | } 9 | -------------------------------------------------------------------------------- /ft_lstadd_front_bonus.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | void ft_lstadd_front(t_list **lst, t_list *new) 4 | { 5 | if (!lst || !new) 6 | return ; 7 | new->next = *lst; 8 | *lst = new; 9 | } 10 | -------------------------------------------------------------------------------- /ft_lstdelone_bonus.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | void ft_lstdelone(t_list *lst, void (*del)(void *)) 4 | { 5 | if (!lst) 6 | return ; 7 | (*del)(lst->content); 8 | free(lst); 9 | } 10 | -------------------------------------------------------------------------------- /ft_lstlast_bonus.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | t_list *ft_lstlast(t_list *lst) 4 | { 5 | if (!lst) 6 | return (NULL); 7 | while (lst->next != NULL) 8 | lst = lst->next; 9 | return (lst); 10 | } 11 | -------------------------------------------------------------------------------- /ft_strchr.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | char *ft_strchr(const char *s, int c) 4 | { 5 | while ((char)c != *s) 6 | { 7 | if (!*s) 8 | return (0); 9 | s++; 10 | } 11 | return ((char *)s); 12 | } 13 | -------------------------------------------------------------------------------- /ft_bzero.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | void ft_bzero(void *s, size_t n) 4 | { 5 | size_t i; 6 | char *str; 7 | 8 | str = s; 9 | i = 0; 10 | while (i < n) 11 | { 12 | str[i] = 0; 13 | i++; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /ft_lstadd_back_bonus.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | void ft_lstadd_back(t_list **lst, t_list *new) 4 | { 5 | if (!lst || !new) 6 | return ; 7 | if (*lst) 8 | ft_lstlast(*lst)->next = new; 9 | else 10 | *lst = new; 11 | } 12 | -------------------------------------------------------------------------------- /ft_putstr_fd.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | void ft_putstr_fd(char *s, int fd) 4 | { 5 | int i; 6 | 7 | i = 0; 8 | if (!s) 9 | return ; 10 | while (s[i]) 11 | { 12 | ft_putchar_fd(s[i], fd); 13 | i++; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /ft_memset.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | void *ft_memset(void *s, int c, size_t n) 4 | { 5 | size_t i; 6 | char *str; 7 | 8 | i = 0; 9 | str = s; 10 | while (i < n) 11 | { 12 | str[i] = c; 13 | i++; 14 | } 15 | return (s); 16 | } 17 | -------------------------------------------------------------------------------- /ft_calloc.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | void *ft_calloc(size_t nmemb, size_t size) 4 | { 5 | void *array; 6 | 7 | array = (void *)malloc(nmemb * size); 8 | if (array == NULL) 9 | return (NULL); 10 | ft_bzero(array, (nmemb * size)); 11 | return (array); 12 | } 13 | -------------------------------------------------------------------------------- /ft_lstsize_bonus.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | int ft_lstsize(t_list *lst) 4 | { 5 | int count; 6 | t_list *node; 7 | 8 | node = lst; 9 | count = 0; 10 | while (node != NULL) 11 | { 12 | count++; 13 | node = node->next; 14 | } 15 | return (count); 16 | } 17 | -------------------------------------------------------------------------------- /ft_striteri.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | void ft_striteri(char *s, void (*f)(unsigned int, 4 | char*)) 5 | { 6 | int i; 7 | 8 | if (!s) 9 | return ; 10 | i = 0; 11 | while (s[i] != '\0') 12 | { 13 | (*f)(i, &s[i]); 14 | i++; 15 | } 16 | s[i] = '\0'; 17 | } 18 | -------------------------------------------------------------------------------- /ft_strrchr.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | char *ft_strrchr(const char *s, int c) 4 | { 5 | int i; 6 | 7 | i = 0; 8 | while (s[i]) 9 | i++; 10 | while (i >= 0) 11 | { 12 | if (s[i] == (char)c) 13 | return ((char *)(s + i)); 14 | i--; 15 | } 16 | return (0); 17 | } 18 | -------------------------------------------------------------------------------- /ft_lstclear_bonus.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | void ft_lstclear(t_list **lst, void (*del)(void *)) 4 | { 5 | t_list *node; 6 | 7 | if (!lst) 8 | return ; 9 | while (*lst) 10 | { 11 | node = (*lst)->next; 12 | ft_lstdelone(*lst, del); 13 | *lst = node; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /ft_lstiter_bonus.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | void ft_lstiter(t_list *lst, void (*f)(void *)) 4 | { 5 | t_list *list_ptr; 6 | 7 | if (!lst) 8 | return ; 9 | list_ptr = lst; 10 | while (list_ptr != NULL) 11 | { 12 | (*f)(list_ptr->content); 13 | list_ptr = list_ptr->next; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /ft_lstnew_bonus.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | t_list *ft_lstnew(void *content) 4 | { 5 | t_list *new_node; 6 | 7 | new_node = (t_list *)malloc(sizeof(t_list)); 8 | if (!new_node) 9 | return (NULL); 10 | new_node->content = content; 11 | new_node->next = NULL; 12 | return (new_node); 13 | } 14 | -------------------------------------------------------------------------------- /ft_memchr.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | void *ft_memchr(const void *s, int c, size_t n) 4 | { 5 | size_t index; 6 | 7 | index = 0; 8 | while (index < n) 9 | { 10 | if (((unsigned char *)s)[index] == (unsigned char)c) 11 | return (((unsigned char *)s) + index); 12 | index++; 13 | } 14 | return (NULL); 15 | } 16 | -------------------------------------------------------------------------------- /ft_strdup.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | char *ft_strdup(const char *src) 4 | { 5 | size_t size; 6 | char *dest; 7 | 8 | size = ft_strlen(src); 9 | dest = (char *)malloc(size * sizeof(char) + 1); 10 | if (dest == NULL) 11 | return (0); 12 | ft_memcpy(dest, src, size); 13 | dest[size] = '\0'; 14 | return (dest); 15 | } 16 | -------------------------------------------------------------------------------- /ft_strlcpy.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | size_t ft_strlcpy(char *dest, const char *src, size_t size) 4 | { 5 | size_t i; 6 | 7 | i = 0; 8 | if (size != 0) 9 | { 10 | while (src [i] != '\0' && i < (size - 1)) 11 | { 12 | dest[i] = src[i]; 13 | i++; 14 | } 15 | dest[i] = '\0'; 16 | } 17 | return (ft_strlen(src)); 18 | } 19 | -------------------------------------------------------------------------------- /ft_putnbr_fd.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | void ft_putnbr_fd(int n, int fd) 4 | { 5 | long nb; 6 | 7 | nb = n; 8 | if (nb < 0) 9 | { 10 | write(fd, "-", 1); 11 | nb *= -1; 12 | } 13 | if (nb > 9) 14 | { 15 | ft_putnbr_fd(nb / 10, fd); 16 | ft_putchar_fd((nb % 10) + '0', fd); 17 | } 18 | else 19 | ft_putchar_fd(nb + '0', fd); 20 | } 21 | -------------------------------------------------------------------------------- /ft_strncmp.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | int ft_strncmp(const char *s1, const char *s2, size_t n) 4 | { 5 | size_t i; 6 | 7 | i = 0; 8 | if (n == 0) 9 | return (0); 10 | while ((i < n) && (s1[i] || s2[i])) 11 | { 12 | if (s1[i] != s2[i]) 13 | return (((unsigned char)s1[i] - (unsigned char)s2[i])); 14 | i++; 15 | } 16 | return (0); 17 | } 18 | -------------------------------------------------------------------------------- /ft_memcpy.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | void *ft_memcpy(void *dest, const void *src, size_t n) 4 | { 5 | size_t i; 6 | 7 | i = 0; 8 | if (!dest && !src) 9 | return (NULL); 10 | if (dest != src) 11 | { 12 | while (i < n) 13 | { 14 | ((unsigned char *)dest)[i] = ((unsigned char *)src)[i]; 15 | i++; 16 | } 17 | } 18 | return (dest); 19 | } 20 | -------------------------------------------------------------------------------- /ft_memcmp.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | int ft_memcmp(const void *s1, const void *s2, size_t n) 4 | { 5 | unsigned char *ptr; 6 | unsigned char *ptr1; 7 | 8 | if (n == 0) 9 | return (0); 10 | ptr = (unsigned char *)s1; 11 | ptr1 = (unsigned char *)s2; 12 | while ((*ptr == *ptr1) && n - 1 > 0) 13 | { 14 | ptr++; 15 | ptr1++; 16 | n--; 17 | } 18 | return ((int)(*ptr - *ptr1)); 19 | } 20 | -------------------------------------------------------------------------------- /ft_strmapi.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | char *ft_strmapi(char const *s, char (*f)(unsigned 4 | int, char)) 5 | { 6 | unsigned int i; 7 | unsigned int length; 8 | char *res; 9 | 10 | if (!s) 11 | return (NULL); 12 | length = ft_strlen(s); 13 | res = malloc(length * sizeof(char) + 1); 14 | if (!res) 15 | return (NULL); 16 | i = 0; 17 | while (i < length) 18 | { 19 | res[i] = (*f)(i, s[i]); 20 | i++; 21 | } 22 | res[i] = '\0'; 23 | return (res); 24 | } 25 | -------------------------------------------------------------------------------- /ft_lstmap_bonus.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)) 4 | { 5 | t_list *new; 6 | t_list *node; 7 | 8 | if (!f || !lst) 9 | return (NULL); 10 | new = NULL; 11 | while (lst) 12 | { 13 | node = ft_lstnew(f(lst->content)); 14 | if (!node) 15 | { 16 | ft_lstclear(&node, (*del)); 17 | return (NULL); 18 | } 19 | ft_lstadd_back(&new, node); 20 | lst = lst->next; 21 | } 22 | return (new); 23 | } 24 | -------------------------------------------------------------------------------- /ft_strlcat.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | size_t ft_strlcat(char *dst, const char *src, size_t size) 4 | { 5 | size_t s; 6 | size_t d; 7 | size_t di; 8 | size_t si; 9 | 10 | si = ft_strlen(src); 11 | if (!dst && size == 0) 12 | return (si); 13 | d = ft_strlen(dst); 14 | di = d; 15 | if (size <= di) 16 | return (size + si); 17 | s = 0; 18 | while (src[s] && d + 1 < size) 19 | { 20 | dst[d] = src[s]; 21 | s++; 22 | d++; 23 | } 24 | dst[d] = 0; 25 | return (di + si); 26 | } 27 | -------------------------------------------------------------------------------- /ft_substr.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | char *ft_substr(char const *s, unsigned int start, size_t len) 4 | { 5 | char *new; 6 | size_t slen; 7 | size_t finish; 8 | 9 | if (!s) 10 | return (0); 11 | slen = ft_strlen(s); 12 | finish = 0; 13 | if (start < slen) 14 | finish = slen - start; 15 | if (finish > len) 16 | finish = len; 17 | new = (char *)malloc(sizeof(char) * (finish + 1)); 18 | if (!new) 19 | return (0); 20 | ft_strlcpy(new, s + start, finish + 1); 21 | return (new); 22 | } 23 | -------------------------------------------------------------------------------- /ft_atoi.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | int ft_atoi(const char *str) 4 | { 5 | int i; 6 | int sign; 7 | unsigned long int result; 8 | 9 | i = 0; 10 | sign = 1; 11 | result = 0; 12 | while (str[i] == 32 || (str[i] >= 9 && str[i] <= 13)) 13 | i++; 14 | if (str[i] == '-') 15 | { 16 | sign = -1; 17 | i++; 18 | } 19 | else if (str[i] == '+') 20 | i++; 21 | while (ft_isdigit(str[i])) 22 | { 23 | result *= 10; 24 | result += str[i] - '0'; 25 | i++; 26 | } 27 | return (result * sign); 28 | } 29 | -------------------------------------------------------------------------------- /ft_strjoin.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | char *ft_strjoin(char const *s1, char const *s2) 4 | { 5 | char *new; 6 | int i; 7 | int j; 8 | 9 | i = 0; 10 | j = 0; 11 | if (!s1 || !s2) 12 | return (NULL); 13 | new = (char *)malloc(sizeof(char) * ft_strlen(s1) + ft_strlen(s2) + 1); 14 | if (!new) 15 | return (NULL); 16 | while (s1[i]) 17 | { 18 | new[i] = s1[i]; 19 | i++; 20 | } 21 | while (s2[j]) 22 | { 23 | new[i] = s2[j]; 24 | i++; 25 | j++; 26 | } 27 | new[i] = '\0'; 28 | return (new); 29 | } 30 | -------------------------------------------------------------------------------- /ft_memmove.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | void *ft_memmove(void *dest, const void *src, size_t n) 4 | { 5 | size_t i; 6 | char j; 7 | unsigned char *d; 8 | unsigned char *s; 9 | 10 | i = 0; 11 | j = 1; 12 | d = (unsigned char *)dest; 13 | s = (unsigned char *)src; 14 | if (!dest && !src) 15 | return (NULL); 16 | if (dest > src) 17 | { 18 | j = -1; 19 | d += n - 1; 20 | s += n - 1; 21 | } 22 | while (i < n) 23 | { 24 | *d = *s; 25 | d += j; 26 | s += j; 27 | i++; 28 | } 29 | return (dest); 30 | } 31 | -------------------------------------------------------------------------------- /ft_strnstr.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | char *ft_strnstr(const char *str, const char *to_find, size_t len) 4 | { 5 | size_t i; 6 | size_t j; 7 | 8 | i = 0; 9 | if (!str && !len) 10 | return (0); 11 | if (to_find[0] == '\0' || to_find == str) 12 | return ((char *)str); 13 | while (str[i] != '\0') 14 | { 15 | j = 0; 16 | while (str[i + j] == to_find[j] && (i + j) < len) 17 | { 18 | if (str[i + j] == '\0' && to_find[j] == '\0') 19 | return ((char *)&str[i]); 20 | j++; 21 | } 22 | if (to_find[j] == '\0') 23 | return ((char *)(str + i)); 24 | i++; 25 | } 26 | return (0); 27 | } 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf 53 | -------------------------------------------------------------------------------- /ft_strtrim.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | static int ft_check_set(char const c, char const *set) 4 | { 5 | int i; 6 | 7 | i = 0; 8 | while (set[i] != '\0') 9 | { 10 | if (set[i] == c) 11 | return (1); 12 | i++; 13 | } 14 | return (0); 15 | } 16 | 17 | char *ft_strtrim(char const *s1, char const *set) 18 | { 19 | size_t size; 20 | char *new; 21 | 22 | if (!s1 || !set) 23 | return (NULL); 24 | while (s1) 25 | { 26 | if (ft_check_set(((char)*s1), set) == 1) 27 | s1++; 28 | else 29 | break ; 30 | } 31 | size = ft_strlen(s1); 32 | while (size != 0) 33 | { 34 | if (ft_check_set(s1[size - 1], set) == 1) 35 | size--; 36 | else 37 | break ; 38 | } 39 | new = (char *)malloc(size * sizeof(char) + 1); 40 | if (!new) 41 | return (NULL); 42 | ft_strlcpy(new, (char *)s1, size + 1); 43 | return (new); 44 | } 45 | -------------------------------------------------------------------------------- /ft_itoa.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | static char *ft_char(char *s, unsigned int number, long int len) 4 | { 5 | while (number > 0) 6 | { 7 | s[len--] = 48 + (number % 10); 8 | number = number / 10; 9 | } 10 | return (s); 11 | } 12 | 13 | static long int ft_len(int n) 14 | { 15 | int len; 16 | 17 | len = 0; 18 | if (n <= 0) 19 | len = 1; 20 | while (n != 0) 21 | { 22 | len++; 23 | n = n / 10; 24 | } 25 | return (len); 26 | } 27 | 28 | char *ft_itoa(int n) 29 | { 30 | char *s; 31 | long int len; 32 | unsigned int number; 33 | int sign; 34 | 35 | sign = 1; 36 | len = ft_len(n); 37 | s = (char *)malloc(sizeof(char) * (len + 1)); 38 | if (!(s)) 39 | return (NULL); 40 | s[len--] = '\0'; 41 | if (n == 0) 42 | s[0] = '0'; 43 | if (n < 0) 44 | { 45 | sign *= -1; 46 | number = n * -1; 47 | s[0] = '-'; 48 | } 49 | else 50 | number = n; 51 | s = ft_char(s, number, len); 52 | return (s); 53 | } 54 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | SRCS = ft_isalpha.c ft_isdigit.c ft_isalnum.c ft_isascii.c \ 2 | ft_isprint.c ft_strlen.c ft_memset.c ft_bzero.c \ 3 | ft_memcpy.c ft_memmove.c ft_strlcpy.c ft_strlcat.c \ 4 | ft_calloc.c ft_strdup.c ft_toupper.c ft_tolower.c \ 5 | ft_strchr.c ft_strncmp.c ft_memchr.c ft_memcmp.c \ 6 | ft_strnstr.c ft_atoi.c ft_strrchr.c ft_substr.c \ 7 | ft_strjoin.c ft_strtrim.c ft_split.c ft_itoa.c \ 8 | ft_strmapi.c ft_striteri.c ft_putchar_fd.c \ 9 | ft_putstr_fd.c ft_putendl_fd.c ft_putnbr_fd.c 10 | SRCSB = ft_lstnew_bonus.c ft_lstadd_front_bonus.c \ 11 | ft_lstsize_bonus.c ft_lstlast_bonus.c \ 12 | ft_lstadd_back_bonus.c ft_lstdelone_bonus.c \ 13 | ft_lstclear_bonus.c ft_lstiter_bonus.c \ 14 | ft_lstmap_bonus.c 15 | OBJS = ${SRCS:.c=.o} 16 | OBJSB = ${SRCSB:.c=.o} 17 | NAME = libft.a 18 | LIBC = ar rcs 19 | CC = cc 20 | RM = rm -f 21 | CFLAGS = -Wall -Wextra -Werror 22 | 23 | .c.o: 24 | ${CC} ${CFLAGS} -c $< -o ${<:.c=.o} 25 | 26 | ${NAME}: ${OBJS} 27 | ${LIBC} ${NAME} ${OBJS} 28 | 29 | all: ${NAME} 30 | 31 | bonus: ${NAME} ${OBJSB} 32 | ${LIBC} ${NAME} ${OBJSB} 33 | clean: 34 | ${RM} ${OBJS} ${OBJSB} 35 | 36 | fclean: clean 37 | ${RM} ${NAME} ${bonus} 38 | 39 | re: fclean all 40 | 41 | .PHONY : all bonus clean fclean re 42 | -------------------------------------------------------------------------------- /ft_split.c: -------------------------------------------------------------------------------- 1 | #include "libft.h" 2 | 3 | static char **free_array(char **ptr, int i) 4 | { 5 | while (i > 0) 6 | { 7 | i--; 8 | free(ptr[i]); 9 | } 10 | free(ptr); 11 | return (0); 12 | } 13 | 14 | static int ft_count_words(char const *str, char c) 15 | { 16 | int i; 17 | int count; 18 | 19 | i = 0; 20 | count = 0; 21 | while (str[i] != '\0') 22 | { 23 | if (str[i] == c) 24 | i++; 25 | else 26 | { 27 | count++; 28 | while (str[i] && str[i] != c) 29 | i++; 30 | } 31 | } 32 | return (count); 33 | } 34 | 35 | static char *ft_putword(char *word, char const *s, int i, int word_len) 36 | { 37 | int j; 38 | 39 | j = 0; 40 | while (word_len > 0) 41 | { 42 | word[j] = s[i - word_len]; 43 | j++; 44 | word_len--; 45 | } 46 | word[j] = '\0'; 47 | return (word); 48 | } 49 | 50 | static char **ft_split_words(char const *s, char c, char **s2, int num_words) 51 | { 52 | int i; 53 | int word; 54 | int word_len; 55 | 56 | i = 0; 57 | word = 0; 58 | word_len = 0; 59 | while (word < num_words) 60 | { 61 | while (s[i] && s[i] == c) 62 | i++; 63 | while (s[i] && s[i] != c) 64 | { 65 | i++; 66 | word_len++; 67 | } 68 | s2[word] = (char *)malloc(sizeof(char) * (word_len + 1)); 69 | if (!s2) 70 | return (free_array(s2, word)); 71 | ft_putword(s2[word], s, i, word_len); 72 | word_len = 0; 73 | word++; 74 | } 75 | s2[word] = 0; 76 | return (s2); 77 | } 78 | 79 | char **ft_split(char const *s, char c) 80 | { 81 | char **s2; 82 | unsigned int num_words; 83 | 84 | if (!s) 85 | return (0); 86 | num_words = ft_count_words(s, c); 87 | s2 = (char **)malloc(sizeof(char *) * (num_words + 1)); 88 | if (!s2) 89 | return (0); 90 | s2 = ft_split_words(s, c, s2, num_words); 91 | return (s2); 92 | } 93 | -------------------------------------------------------------------------------- /libft.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBFT_H 2 | # define LIBFT_H 3 | # include 4 | # include 5 | # include 6 | # include 7 | 8 | typedef struct s_list 9 | { 10 | void *content; 11 | struct s_list *next; 12 | } t_list; 13 | 14 | int ft_isalpha(int c); 15 | int ft_isdigit(int c); 16 | int ft_isalnum(int c); 17 | int ft_isascii(int c); 18 | int ft_isprint(int c); 19 | int ft_toupper(int c); 20 | int ft_tolower(int c); 21 | int ft_atoi(const char *str); 22 | int ft_lstsize(t_list *lst); 23 | int ft_strncmp(const char *s1, const char *s2, size_t n); 24 | int ft_memcmp(const void *s1, const void *s2, size_t n); 25 | char *ft_itoa(int n); 26 | char *ft_strdup(const char *src); 27 | char *ft_strchr(const char *s, int c); 28 | char *ft_strrchr(const char *s, int c); 29 | char *ft_strnstr(const char *str, const char *to_find, size_t len); 30 | char *ft_substr(char const *s, unsigned int start, size_t len); 31 | char *ft_strjoin(char const *s1, char const *s2); 32 | char *ft_strtrim(char const *s1, char const *set); 33 | char **ft_split(char const *s, char c); 34 | char *ft_strmapi(char const *s, char (*f)(unsigned int, char)); 35 | void ft_putchar_fd(char c, int fd); 36 | void ft_putstr_fd(char *s, int fd); 37 | void ft_putendl_fd(char *s, int fd); 38 | void ft_putnbr_fd(int n, int fd); 39 | void *ft_memset(void *s, int c, size_t n); 40 | void ft_bzero(void *s, size_t n); 41 | void *ft_memcpy(void *dest, const void *src, size_t n); 42 | void *ft_memmove(void *dest, const void *src, size_t n); 43 | void *ft_memchr(const void *s, int c, size_t n); 44 | void *ft_calloc(size_t nmemb, size_t size); 45 | void ft_striteri(char *s, void (*f)(unsigned int, char*)); 46 | void ft_lstadd_front(t_list **lst, t_list *new); 47 | void ft_lstadd_back(t_list **alst, t_list *new); 48 | void ft_lstdelone(t_list *lst, void (*del)(void *)); 49 | void ft_lstclear(t_list **lst, void (*del)(void *)); 50 | void ft_lstiter(t_list *lst, void (*f)(void *)); 51 | size_t ft_strlen(const char *str); 52 | size_t ft_strlcpy(char *dest, const char *src, size_t size); 53 | size_t ft_strlcat(char *dest, const char *src, size_t size); 54 | t_list *ft_lstnew(void *content); 55 | t_list *ft_lstlast(t_list *lst); 56 | t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)); 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Libft-42 2 | This project aims to code a C library regrouping usual functions that we’ll be allowed to use in all our other 42 projects. 3 | # Resources 4 | Makefile
5 | https://makefiletutorial.com/

https://gl.developpez.com/tutoriel/outil/makefile/

http://perso.univ-lyon1.fr/jean-claude.iehl/Public/educ/Makefile.html

Typecasting
https://www.tutorialspoint.com/cprogramming/c_type_casting.htm

https://zhu45.org/posts/2017/Jan/19/typecasting-in-c/

https://developerinsider.co/type-casting-c-programming/

https://www.geeksforgeeks.org/typecasting-in-c/

Memory
https://www.geeksforgeeks.org/memory-layout-of-c-program/

https://craftofcoding.wordpress.com/2015/12/07/memory-in-c-the-stack-the-heap-and-static/

https://www.gnu.org/software/libc/manual/html_node/Memory-Allocation-and-C.html

https://openclassrooms.com/fr/courses/19980-apprenez-a-programmer-en-c/16595-lallocation-dynamique

https://rperrot.developpez.com/articles/c/allocationC/

https://waytolearnx.com/2019/03/difference-entre-allocation-dynamique-et-allocation-statique.html

https://buzut.net/cours/computer-science/differents-types-de-memoires

https://www.it-swarm-fr.com/fr/c/difference-entre-lallocation-de-memoire-statique-et-lallocation-de-memoire-dynamique/940988866/

http://www.cs.ru.nl/~erikpoll/sws1/slides/hic4.pdf 6 | 7 | 8 | Pointers
9 | https://www.geeksforgeeks.org/void-pointer-c-cpp/?ref=lbp/

https://www.geeksforgeeks.org/dangling-void-null-wild-pointers/

https://www.javatpoint.com/c-dereference-pointer

Functions
https://webdevdesigner.com/q/what-is-the-difference-between-memcmp-strcmp-and-strncmp-in-c-102548/

https://pvs-studio.com/en/blog/posts/cpp/0360/

https://www.geeksforgeeks.org/what-are-static-functions-in-c/

https://www.cs.utah.edu/~germain/PPS/Topics/C_Language/c_functions.html

Data types
10 | https://web.maths.unsw.edu.au/~lafaye/CCM/c/ctype.htm

https://www.arm.linux.org.uk/docs/faqs/signedchar.php

Errors
https://www.geeksforgeeks.org/segmentation-fault-sigsegv-vs-bus-error-sigbus/ 11 | 12 | https://www.geeksforgeeks.org/program-error-signals/

https://www.educba.com/types-of-errors-in-c/

http://www.yolinux.com/TUTORIALS/C++Signals.html 13 | 14 | 15 | File descriptor
16 | https://www.geeksforgeeks.org/input-output-system-calls-c-create-open-close-read-write/

Linked list
17 | https://www.geeksforgeeks.org/data-structures/linked-list/

Others
https://www.exploit-db.com/docs/english/28477-linux-integer-overflow-and-underflow.pdf 18 | 19 | https://www.lri.fr/~hivert/COURS/CFA-L3/02-Recursivite.pdf 20 | 21 | 22 | Books:
23 | The C programming Language. -Brian Kernighan et Dennis Ritchie. 24 | 25 | Apprenez à programmer en C. -Mathieu Nebra. 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | --------------------------------------------------------------------------------