Added a couple of wanted functions.
authorLukas Jiriste <ljiriste@student.42prague.com>
Mon, 14 Aug 2023 11:45:12 +0000 (13:45 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Mon, 14 Aug 2023 11:45:12 +0000 (13:45 +0200)
Also added 2 additional functions - islower and isupper.
These functions naturaly fit in and are used for more readible implementation of other functions.
Each .c file includes the library header libft.h (libft.h is not added in this commit).

12 files changed:
ft_bzero.c [new file with mode: 0644]
ft_isalnum.c [new file with mode: 0644]
ft_isalpha.c [new file with mode: 0644]
ft_isdigit.c [new file with mode: 0644]
ft_islower.c [new file with mode: 0644]
ft_isupper.c [new file with mode: 0644]
ft_memcpy.c [new file with mode: 0644]
ft_memmove.c [new file with mode: 0644]
ft_memset.c [new file with mode: 0644]
ft_strlcat.c [new file with mode: 0644]
ft_strlcpy.c [new file with mode: 0644]
ft_strlen.c [new file with mode: 0644]

diff --git a/ft_bzero.c b/ft_bzero.c
new file mode 100644 (file)
index 0000000..9346d4b
--- /dev/null
@@ -0,0 +1,20 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_bzero.c                                         :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/14 13:38:08 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/08/14 13:38:32 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include <sys/types.h>
+#include "libft.h"
+
+void   ft_bzero(void *s, size_t n)
+{
+       ft_memset(s, 0, n);
+       return ;
+}
diff --git a/ft_isalnum.c b/ft_isalnum.c
new file mode 100644 (file)
index 0000000..fd9ed56
--- /dev/null
@@ -0,0 +1,18 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_isalnum.c                                       :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/14 13:02:16 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/08/14 13:34:41 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+int    ft_isalnum(int c)
+{
+       return (ft_isdigit(c) || ft_isalpha(c));
+}
diff --git a/ft_isalpha.c b/ft_isalpha.c
new file mode 100644 (file)
index 0000000..c3a3ebc
--- /dev/null
@@ -0,0 +1,18 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_isalpha.c                                       :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/14 13:32:19 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/08/14 13:32:33 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+int    ft_isalpha(int c)
+{
+       return (ft_isupper(c) || ft_islower(c));
+}
diff --git a/ft_isdigit.c b/ft_isdigit.c
new file mode 100644 (file)
index 0000000..6df7e2c
--- /dev/null
@@ -0,0 +1,18 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_isdigit.c                                       :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/14 13:32:47 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/08/14 13:33:02 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+int    ft_isdigit(int c)
+{
+       return ('0' <= c && c <= '9');
+}
diff --git a/ft_islower.c b/ft_islower.c
new file mode 100644 (file)
index 0000000..ebcf47d
--- /dev/null
@@ -0,0 +1,18 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_islower.c                                       :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/14 13:31:47 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/08/14 13:32:05 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+static int     ft_islower(int c)
+{
+       return ('a' <= c && c <= 'z');
+}
diff --git a/ft_isupper.c b/ft_isupper.c
new file mode 100644 (file)
index 0000000..4a9acd2
--- /dev/null
@@ -0,0 +1,18 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_isupper.c                                       :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/14 13:31:05 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/08/14 13:31:31 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+static int     ft_isupper(int c)
+{
+       return ('A' <= c && c <= 'Z');
+}
diff --git a/ft_memcpy.c b/ft_memcpy.c
new file mode 100644 (file)
index 0000000..e4d2b2c
--- /dev/null
@@ -0,0 +1,24 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_memcpy.c                                        :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/14 13:35:59 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/08/14 13:36:20 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include <sys/types.h>
+#include "libft.h"
+
+void   *ft_memcpy(void *dest, const void *src, size_t n)
+{
+       while (n > 0)
+       {
+               --n;
+               *((unsigned char *)dest + n) = *((unsigned char *)src + n);
+       }
+       return (dest);
+}
diff --git a/ft_memmove.c b/ft_memmove.c
new file mode 100644 (file)
index 0000000..83692d1
--- /dev/null
@@ -0,0 +1,32 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_memmove.c                                       :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/14 13:36:32 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/08/14 13:37:03 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include <sys/types.h>
+#include "libft.h"
+
+void *ft_memmove(void *dest, const void *src, size_t n)
+{
+       size_t  i;
+
+       if (dest > src)
+               ft_memcpy(dest, src, n);
+       else if (dest < src)
+       {
+               i = 0;
+               while (i < n)
+               {
+                       *((unsigned char *)dest + i) = *((unsigned char *)src + i);
+                       ++i;
+               }
+       }
+       return (dest);
+}
diff --git a/ft_memset.c b/ft_memset.c
new file mode 100644 (file)
index 0000000..bfa0468
--- /dev/null
@@ -0,0 +1,21 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_memset.c                                        :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/14 13:13:22 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/08/14 13:38:38 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include <sys/types.h>
+#include "libft.h"
+
+void   *ft_memset(void *s, int c, size_t n)
+{
+       while (n > 0)
+               *((unsigned char *)s + (--n)) = c;
+       return (s);
+}
diff --git a/ft_strlcat.c b/ft_strlcat.c
new file mode 100644 (file)
index 0000000..ed6e7b5
--- /dev/null
@@ -0,0 +1,42 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_strlcat.c                                       :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/06/12 17:32:33 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/08/14 13:39:39 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include <sys/types.h>
+#include "libft.h"
+
+size_t ft_strlcat(char *dst, char *src, size_t size)
+{
+       size_t  length;
+
+       length = 0;
+       while (*dst != '\0' && size > 1)
+       {
+               ++dst;
+               ++length;
+               --size;
+       }
+       while (*src != '\0' && size > 1)
+       {
+               *dst = *src;
+               ++src;
+               ++dst;
+               ++length;
+               --size;
+       }
+       while (size > 0)
+       {
+               *dst = '\0';
+               ++dst;
+               --size;
+       }
+       return (length);
+}
diff --git a/ft_strlcpy.c b/ft_strlcpy.c
new file mode 100644 (file)
index 0000000..3f1d16c
--- /dev/null
@@ -0,0 +1,29 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_strlcpy.c                                       :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/06/11 17:28:43 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/08/14 13:29:38 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include <sys/types.h>
+#include "libft.h"
+
+size_t ft_strlcpy(char *dst, char *src, size_t size)
+{
+       size_t  i;
+
+       i = 0;
+       while (*src != '\0' && i + 1 < size)
+       {
+               dst[i] = src[i];
+               ++i;
+       }
+       if (size > 0)
+               dst[i] = '\0';
+       return (ft_strlen(src));
+}
diff --git a/ft_strlen.c b/ft_strlen.c
new file mode 100644 (file)
index 0000000..f4ae6c7
--- /dev/null
@@ -0,0 +1,24 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_strlen.c                                        :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/14 13:40:59 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/08/14 13:41:35 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include <sys/types.h>
+#include "libft.h"
+
+size_t ft_strlen(const char *s)
+{
+       size_t  len;
+
+       len = 0;
+       while (s[len] != '\0')
+               ++len;
+       return len;
+}