ALMOST ALL
This commit is contained in:
parent
8bbb452128
commit
8c6fb84472
|
@ -0,0 +1,91 @@
|
|||
CC = cc
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
LDFLAGS =
|
||||
AR = ar rcs
|
||||
RM = /bin/rm -f
|
||||
|
||||
NAME = libft.a
|
||||
OBJDIR = .
|
||||
SRCDIR = .
|
||||
INCDIR = .
|
||||
|
||||
unexport _SRC
|
||||
_SRC += ft_atoi.c
|
||||
_SRC += ft_bzero.c
|
||||
_SRC += ft_calloc.c
|
||||
_SRC += ft_isalnum.c
|
||||
_SRC += ft_isalpha.c
|
||||
_SRC += ft_isascii.c
|
||||
_SRC += ft_isdigit.c
|
||||
_SRC += ft_isprint.c
|
||||
_SRC += ft_isspace.c
|
||||
_SRC += ft_memchr.c
|
||||
_SRC += ft_memcmp.c
|
||||
_SRC += ft_memcpy.c
|
||||
_SRC += ft_memmove.c
|
||||
_SRC += ft_memset.c
|
||||
_SRC += ft_strchr.c
|
||||
_SRC += ft_strdup.c
|
||||
_SRC += ft_strlcat.c
|
||||
_SRC += ft_strlcpy.c
|
||||
_SRC += ft_strlen.c
|
||||
_SRC += ft_strncmp.c
|
||||
_SRC += ft_strnstr.c
|
||||
_SRC += ft_strrchr.c
|
||||
_SRC += ft_tolower.c
|
||||
_SRC += ft_toupper.c
|
||||
# _SRC += ft_putchar_fd.c
|
||||
# _SRC += ft_putendl_fd.c
|
||||
# _SRC += ft_putnbr_fd.c
|
||||
# _SRC += ft_putstr_fd.c
|
||||
|
||||
# _SRC += ft_itoa.c
|
||||
# _SRC += ft_strtrim.c
|
||||
_SRC += ft_substr.c
|
||||
# _SRC += ft_strjoin.c
|
||||
# _SRC += ft_split.c
|
||||
# _SRC += ft_striteri.c
|
||||
# _SRC += ft_strmapi.c
|
||||
|
||||
# _SRC += ft_lstadd_back.c
|
||||
# _SRC += ft_lstadd_front.c
|
||||
# _SRC += ft_lstclear
|
||||
# _SRC += ft_lstdelone.c
|
||||
# _SRC += ft_lstiter.c
|
||||
# _SRC += ft_lstlast.c
|
||||
# _SRC += ft_lstmap.c
|
||||
# _SRC += ft_lstnew.c
|
||||
# _SRC += ft_lstsize.c
|
||||
|
||||
unexport _DEPS
|
||||
_DEPS += libft.h
|
||||
|
||||
_OBJ = $(_SRC:.c=.o)
|
||||
|
||||
OBJ = $(addprefix $(OBJDIR)/,$(_OBJ))
|
||||
SRC = $(addprefix $(SRCDIR)/,$(_SRC))
|
||||
DEPS = $(addprefix $(INCDIR)/,$(_DEPS))
|
||||
|
||||
so:
|
||||
$(CC) -nostartfiles -fPIC $(CFLAGS) $(SRC)
|
||||
gcc -nostartfiles -shared -o libft.so $(OBJ)
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
$(NAME): $(OBJ)
|
||||
$(AR) $@ $^
|
||||
|
||||
$(OBJDIR)/%.o: %c $(DEPS)
|
||||
$(CC) $(CFLAGS) -c -o $@ -I$(INCDIR) $<
|
||||
|
||||
clean:
|
||||
$(RM) $(OBJ)
|
||||
|
||||
fclean: clean
|
||||
$(RM) $(NAME)
|
||||
|
||||
re: fclean all
|
||||
|
||||
bonus: all
|
||||
|
||||
.PHONY: re fclean clean all bonus
|
|
@ -0,0 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/05/22 17:28:18 by tosuman #+# #+# */
|
||||
/* Updated: 2023/05/22 17:28:18 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_isspace(int c);
|
||||
int ft_isdigit(int c);
|
||||
|
||||
int ft_atoi(const char *nptr)
|
||||
{
|
||||
int res;
|
||||
int sign;
|
||||
|
||||
while (ft_isspace(*nptr++))
|
||||
;
|
||||
sign = 1;
|
||||
if (*--nptr == '+' || *nptr == '-')
|
||||
if (*nptr++ == '-')
|
||||
sign = -1;
|
||||
res = 0;
|
||||
while (ft_isdigit(*nptr))
|
||||
res = res * 10 + *nptr++ - '0';
|
||||
return (sign * res);
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_bzero.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/05/11 11:55:27 by tosuman #+# #+# */
|
||||
/* Updated: 2023/05/11 11:55:28 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
void ft_bzero(void *s, size_t n)
|
||||
{
|
||||
while (n--)
|
||||
*(char *) s++ = (unsigned char) 0;
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,37 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_calloc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/05/22 17:39:55 by tosuman #+# #+# */
|
||||
/* Updated: 2023/05/22 17:39:56 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
|
||||
void ft_bzero(void *s, size_t n);
|
||||
|
||||
void *ft_calloc(size_t nmemb, size_t size)
|
||||
{
|
||||
void *ret;
|
||||
void *empty;
|
||||
|
||||
if (nmemb * size == 0)
|
||||
{
|
||||
empty = malloc(0);
|
||||
if (!empty)
|
||||
return (0);
|
||||
return (empty);
|
||||
}
|
||||
if (UINT_MAX / nmemb < size)
|
||||
return (0);
|
||||
ret = malloc(nmemb * size);
|
||||
if (!ret)
|
||||
return (0);
|
||||
ft_bzero(ret, nmemb * size);
|
||||
return (ret);
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,21 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isspace.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/05/22 17:38:55 by tosuman #+# #+# */
|
||||
/* Updated: 2023/05/22 17:39:02 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_isspace(int c)
|
||||
{
|
||||
return (c == ' '
|
||||
|| c == '\n'
|
||||
|| c == '\r'
|
||||
|| c == '\t'
|
||||
|| c == '\f'
|
||||
|| c == '\v');
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/05/22 16:34:06 by tosuman #+# #+# */
|
||||
/* Updated: 2023/05/22 16:34:06 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
void *ft_memchr(const void *s, int c, size_t n)
|
||||
{
|
||||
unsigned char *us;
|
||||
|
||||
us = (unsigned char *) s;
|
||||
while (n--)
|
||||
if (*us++ == (unsigned char) c)
|
||||
return (--us);
|
||||
return (0);
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,28 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/05/22 16:44:15 by tosuman #+# #+# */
|
||||
/* Updated: 2023/05/22 16:44:15 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
int ft_memcmp(const void *s1, const void *s2, size_t n)
|
||||
{
|
||||
unsigned char *us1;
|
||||
unsigned char *us2;
|
||||
|
||||
us1 = (unsigned char *) s1;
|
||||
us2 = (unsigned char *) s2;
|
||||
if (!n)
|
||||
return (0);
|
||||
while (n--)
|
||||
if (*us1++ != *us2++)
|
||||
return (*--us1 - *--us2);
|
||||
return (0);
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,27 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/05/11 13:28:20 by tosuman #+# #+# */
|
||||
/* Updated: 2023/05/11 13:28:21 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
void *ft_memcpy(void *dest, const void *src, size_t n)
|
||||
{
|
||||
char *d;
|
||||
const char *s;
|
||||
|
||||
if (!src && !dest)
|
||||
return (0);
|
||||
d = dest;
|
||||
s = src;
|
||||
while (n--)
|
||||
*d++ = *s++;
|
||||
return (dest);
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,32 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memmove.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/05/11 16:19:10 by tosuman #+# #+# */
|
||||
/* Updated: 2023/05/11 16:19:11 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
|
||||
void *ft_memmove(void *dest, const void *src, size_t n)
|
||||
{
|
||||
char *d;
|
||||
const char *s;
|
||||
|
||||
if (!src && !dest)
|
||||
return (0);
|
||||
d = dest;
|
||||
s = src;
|
||||
if (src >= dest)
|
||||
while (n--)
|
||||
*d++ = *s++;
|
||||
else
|
||||
while (n--)
|
||||
*(d + n) = *(s + n);
|
||||
return (dest);
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,23 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memset.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/05/11 10:06:42 by tosuman #+# #+# */
|
||||
/* Updated: 2023/05/11 10:06:42 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
void *ft_memset(void *s, int c, unsigned long n)
|
||||
{
|
||||
unsigned char *ptr;
|
||||
|
||||
ptr = (unsigned char *) s;
|
||||
while (n-- > 0)
|
||||
*ptr++ = c;
|
||||
return (s);
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,22 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/05/22 16:20:31 by tosuman #+# #+# */
|
||||
/* Updated: 2023/05/22 16:20:33 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
char *ft_strchr(const char *s, int c)
|
||||
{
|
||||
while (*s)
|
||||
if (*s++ == (unsigned char) c)
|
||||
return ((char *)--s);
|
||||
if (*s == (unsigned char) c)
|
||||
return ((char *) s);
|
||||
else
|
||||
return (0);
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,29 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strdup.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/05/22 19:12:24 by tosuman #+# #+# */
|
||||
/* Updated: 2023/05/22 19:15:06 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
size_t ft_strlen(const char *s);
|
||||
size_t ft_strlcpy(char *dst, const char *src, size_t size);
|
||||
|
||||
char *ft_strdup(const char *s)
|
||||
{
|
||||
char *s2;
|
||||
size_t len;
|
||||
|
||||
len = ft_strlen(s);
|
||||
s2 = malloc(sizeof(char) * (len + 1));
|
||||
if (!s2)
|
||||
return (0);
|
||||
ft_strlcpy(s2, (char *) s, len + 1);
|
||||
return (s2);
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,27 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strjoin.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/05/24 13:43:29 by tosuman #+# #+# */
|
||||
/* Updated: 2023/05/24 13:43:30 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strjoin(char const *s1, char const s2)
|
||||
{
|
||||
size_t total_len;
|
||||
char *joined_str;
|
||||
|
||||
total_len = ft_strlen(s1) + ft_strlen(s2);
|
||||
joined_str = ft_calloc(sizeof(char) * (total_len + 1));
|
||||
if (!joined_str)
|
||||
return (0);
|
||||
ft_strlcpy(joined_str, s1, total_len);
|
||||
ft_strlcat(joined_str, s2, total_len);
|
||||
return (joined_str);
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlcat.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/05/11 16:55:00 by tosuman #+# #+# */
|
||||
/* Updated: 2023/05/11 16:55:01 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
size_t ft_strlcat(char *dst, const char *src, size_t size)
|
||||
{
|
||||
size_t idx;
|
||||
size_t slen;
|
||||
size_t dlen;
|
||||
|
||||
idx = 0;
|
||||
while (dst[idx])
|
||||
++idx;
|
||||
dlen = idx;
|
||||
if (dlen > size)
|
||||
return (size);
|
||||
slen = 0;
|
||||
while (src[slen])
|
||||
dst[idx++] = src[slen++];
|
||||
return (dlen + slen);
|
||||
}
|
||||
|
||||
// #include <bsd/string.h>
|
||||
// #include <stdio.h>
|
||||
// int main()
|
||||
// {
|
||||
// printf("%d", ft_strlcat());
|
||||
// printf("%d", ft_strlcat());
|
||||
// return (0);
|
||||
// }
|
||||
|
||||
/*
|
||||
Alternative implementation
|
||||
size_t ft_strlcat(char *dst, const char *src, size_t size)
|
||||
{
|
||||
size_t dst_len;
|
||||
size_t src_len;
|
||||
|
||||
if ((!dst || !src) && size == 0)
|
||||
return (0);
|
||||
dst_len = 0;
|
||||
src_len = -1;
|
||||
while (*dst++)
|
||||
++dst_len;
|
||||
while (src[++src_len])
|
||||
;
|
||||
if (size <= dst_len)
|
||||
return (size + src_len);
|
||||
if (--dst && dst_len > size)
|
||||
return (size + dst_len);
|
||||
while (src_len-- && ++dst_len < size)
|
||||
*dst++ = *src++;
|
||||
if (dst_len-- == size)
|
||||
--dst_len;
|
||||
*dst = 0;
|
||||
return (dst_len + src_len);
|
||||
}
|
||||
*/
|
Binary file not shown.
|
@ -0,0 +1,29 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/05/11 16:55:00 by tosuman #+# #+# */
|
||||
/* Updated: 2023/05/11 16:55:01 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
size_t ft_strlcpy(char *dst, const char *src, size_t size)
|
||||
{
|
||||
char *d;
|
||||
size_t len;
|
||||
|
||||
d = dst;
|
||||
len = 0;
|
||||
while (++len < size && *src)
|
||||
*d++ = *src++;
|
||||
if (size)
|
||||
*d = 0;
|
||||
while (*src && src++)
|
||||
len++;
|
||||
return (len - 1);
|
||||
}
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,34 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strncmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/05/22 16:29:43 by tosuman #+# #+# */
|
||||
/* Updated: 2023/05/22 16:29:44 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int ft_strncmp(const char *s1, const char *s2, size_t n)
|
||||
{
|
||||
unsigned char *us1;
|
||||
unsigned char *us2;
|
||||
|
||||
if (!n)
|
||||
return (0);
|
||||
us1 = (unsigned char *) s1;
|
||||
us2 = (unsigned char *) s2;
|
||||
while (*us1 && *us2 && *us1 == *us2 && --n)
|
||||
{
|
||||
us1++;
|
||||
us2++;
|
||||
}
|
||||
if (*us1 != *us2)
|
||||
return ((*us1 - *us2 != 0)
|
||||
* (-2 * (*us1 - *us2 < 0) + 1));
|
||||
return (0);
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,38 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strnstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/05/22 17:05:27 by tosuman #+# #+# */
|
||||
/* Updated: 2023/05/22 17:05:28 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
size_t ft_strlen(const char *s);
|
||||
int ft_memcmp(const void *s1, const void *s2, size_t n);
|
||||
|
||||
char *ft_strnstr(const char *big, const char *little, size_t len)
|
||||
{
|
||||
size_t l_len;
|
||||
size_t b_len;
|
||||
|
||||
if ((!big || !little) && len == 0)
|
||||
return (0);
|
||||
b_len = ft_strlen(big);
|
||||
l_len = ft_strlen(little);
|
||||
if (b_len < l_len || len < l_len)
|
||||
return (0);
|
||||
if (b_len - l_len + 1 < len)
|
||||
len = b_len - l_len + 1;
|
||||
else if (len >= l_len)
|
||||
len = len - l_len;
|
||||
len += !len;
|
||||
while (len--)
|
||||
if (!ft_memcmp(big++, little, l_len))
|
||||
return ((char *)--big);
|
||||
return (0);
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strrchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/05/22 16:24:42 by tosuman #+# #+# */
|
||||
/* Updated: 2023/05/22 16:24:42 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
char *ft_strrchr(const char *s, int c)
|
||||
{
|
||||
char *last;
|
||||
|
||||
last = 0;
|
||||
while (*s)
|
||||
if (*s++ == (char) c)
|
||||
last = (char *)(s - 1);
|
||||
if (*s == (char) c)
|
||||
return ((char *) s);
|
||||
return (last);
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,43 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_substr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/05/24 13:23:00 by tosuman #+# #+# */
|
||||
/* Updated: 2023/05/24 13:23:01 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
void *ft_calloc(size_t nmemb, size_t size);
|
||||
size_t ft_strlcpy(char *dst, const char *src, size_t size);
|
||||
|
||||
char *ft_substr(char const *s, unsigned int start, size_t len)
|
||||
{
|
||||
unsigned int idx;
|
||||
size_t real_len;
|
||||
char *substr;
|
||||
char *empty;
|
||||
|
||||
idx = -1;
|
||||
while (s[++idx] && idx < start)
|
||||
;
|
||||
if (!s[idx])
|
||||
{
|
||||
empty = ft_calloc(1, sizeof(char));
|
||||
if (!empty)
|
||||
return (0);
|
||||
return (empty);
|
||||
}
|
||||
real_len = 0;
|
||||
while (++real_len <= len && s[idx + real_len - 1])
|
||||
;
|
||||
substr = malloc(sizeof(char) * real_len);
|
||||
if (!substr)
|
||||
return (0);
|
||||
ft_strlcpy(substr, s + idx, real_len);
|
||||
return (substr);
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,18 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_tolower.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/05/16 14:37:20 by tosuman #+# #+# */
|
||||
/* Updated: 2023/05/16 14:37:40 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_tolower(int c)
|
||||
{
|
||||
if (c >= 'A' && c <= 'Z')
|
||||
return (c + 32);
|
||||
return (c);
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,18 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_toupper.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/05/22 16:12:47 by tosuman #+# #+# */
|
||||
/* Updated: 2023/05/22 16:12:47 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_toupper(int c)
|
||||
{
|
||||
if (c >= 'a' && c <= 'z')
|
||||
return (c - 32);
|
||||
return (c);
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,50 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* libft.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/05/11 11:31:44 by tosuman #+# #+# */
|
||||
/* Updated: 2023/05/11 11:31:46 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LIBFT_H
|
||||
# define LIBFT_H
|
||||
|
||||
# include <stddef.h>
|
||||
|
||||
int ft_atoi(const char *nptr);
|
||||
void ft_bzero(void *s, size_t n);
|
||||
void *ft_calloc(size_t nmemb, size_t size);
|
||||
int ft_isalnum(int c);
|
||||
int ft_isalpha(int c);
|
||||
int ft_isascii(int c);
|
||||
int ft_isdigit(int c);
|
||||
int ft_isprint(int c);
|
||||
int ft_isspace(int c);
|
||||
void *ft_memchr(const void *s, int c, size_t n);
|
||||
int ft_memcmp(const void *s1, const void *s2, size_t n);
|
||||
void *ft_memcpy(void *dest, const void *src, size_t n);
|
||||
void *ft_memmove(void *dest, const void *src, size_t n);
|
||||
void *ft_memset(void *s, int c, size_t n);
|
||||
char *ft_strchr(const char *s, int c);
|
||||
char *ft_strdup(const char *s);
|
||||
size_t ft_strlcat(char *dst, const char *src, size_t size);
|
||||
size_t ft_strlcpy(char *dst, const char *src, size_t size);
|
||||
size_t ft_strlen(const char *s);
|
||||
int ft_strncmp(const char *s1, const char *s2, size_t n);
|
||||
char *ft_strnstr(const char *big, const char *little, size_t len);
|
||||
char *ft_strrchr(const char *s, int c);
|
||||
int ft_tolower(int c);
|
||||
int ft_toupper(int c);
|
||||
char *ft_substr(char const *s, unsigned int start, size_t len);
|
||||
|
||||
typedef struct s_list
|
||||
{
|
||||
void *content;
|
||||
struct s_list *next;
|
||||
} t_list;
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue