summaryrefslogtreecommitdiff
path: root/ft_getline_utils.c
diff options
context:
space:
mode:
authoryctct <yctct@yctct.com>2026-02-17 09:20:01 +0100
committeryctct <yctct@yctct.com>2026-02-17 09:20:01 +0100
commit7fd21dc25dc31a3807962a3d1489fbfcb951b717 (patch)
treec8e48844290a95fe672a09cd48815b39108ea297 /ft_getline_utils.c
Add files, first commitHEADmain
Diffstat (limited to 'ft_getline_utils.c')
-rw-r--r--ft_getline_utils.c137
1 files changed, 137 insertions, 0 deletions
diff --git a/ft_getline_utils.c b/ft_getline_utils.c
new file mode 100644
index 0000000..d16dae1
--- /dev/null
+++ b/ft_getline_utils.c
@@ -0,0 +1,137 @@
+/*
+ft_getline Copyright (C) 2026 yctct
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+
+#include "ft_getline.h"
+
+char *ft_strchr(const char *s, int c)
+{
+ size_t i;
+ size_t size;
+
+ size = 0;
+ while (s[size])
+ size++;
+ i = 0;
+ while (i <= size)
+ {
+ if (s[i] == (char)c)
+ return ((char *)&s[i]);
+ i++;
+ }
+ return (0);
+}
+char *ft_strjoin(char *s1, char *s2)
+{
+ char *ptr;
+ int len_s1;
+ int len_s2;
+
+ len_s1 = 0;
+ while (s1[len_s1])
+ len_s1++;
+ len_s2 = 0;
+ while (s2[len_s2])
+ len_s2++;
+ ptr = malloc(sizeof(char) * (len_s1 + len_s2 + 1));
+ if (!ptr)
+ {
+ free(s1);
+ return (NULL);
+ }
+ ft_strlcpy(ptr, s1, (len_s1 + 1));
+ ft_strlcat(ptr, s2, (len_s1 + len_s2 + 1));
+ free(s1);
+ return (ptr);
+}
+
+size_t ft_strlcat(char *dest, const char *src, size_t size)
+{
+ size_t dlen;
+ size_t slen;
+
+ dlen = 0;
+ while (dest[dlen])
+ dlen++;
+ slen = 0;
+ while (src[slen])
+ slen++;
+ if (dlen >= size)
+ return (size + slen);
+ if (slen < size - dlen)
+ ft_memcpy(dest + dlen, src, slen + 1);
+ else
+ {
+ ft_memcpy(dest + dlen, src, size - dlen - 1);
+ dest[size - 1] = '\0';
+ }
+ return (dlen + slen);
+}
+
+void *ft_memcpy(void *dest, const void *src, size_t n)
+{
+ unsigned char *a;
+ const char *b;
+
+ if (n == 0)
+ return (dest);
+ if (!dest || !src)
+ return (dest);
+ a = dest;
+ b = src;
+ while (n > 0)
+ {
+ *a++ = *b++;
+ n--;
+ }
+ return (dest);
+}
+
+size_t ft_strlcpy(char *dest, const char *src, size_t size)
+{
+ unsigned int i;
+
+ i = 0;
+ if (size > 0)
+ {
+ while (src[i] && i < (size - 1))
+ {
+ dest[i] = src[i];
+ i++;
+ }
+ dest[i] = '\0';
+ }
+ i = 0;
+ while (src[i])
+ i++;
+ return (i);
+}
+
+char *ft_strdup(const char *s)
+{
+ char *ptr;
+ int len;
+
+ len = 0;
+ while (s[len])
+ len++;
+ ptr = (char *)malloc(len + 1);
+ if (!ptr)
+ return (NULL);
+ ft_strlcpy(ptr, s, len + 1);
+ return (ptr);
+}