-
Notifications
You must be signed in to change notification settings - Fork 10
/
get_next_line_utils_bonus.c
77 lines (67 loc) · 1.86 KB
/
get_next_line_utils_bonus.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jaeskim <jaeskim@student.42seoul.kr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/03 17:49:10 by jaeskim #+# #+# */
/* Updated: 2020/10/04 00:16:11 by jaeskim ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line_bonus.h"
size_t ft_strlen(const char *s)
{
size_t len;
len = 0;
while (*s++)
len++;
return (len);
}
void *ft_memcpy(void *dest, const void *src, size_t n)
{
unsigned char *dp;
const unsigned char *sp;
if (!dest && !src)
return (0);
dp = dest;
sp = src;
while (n-- > 0)
{
*dp++ = *sp++;
}
return (dest);
}
char *ft_strjoin(char const *s1, char const *s2)
{
size_t len1;
size_t len2;
char *result;
len1 = ft_strlen(s1);
len2 = ft_strlen(s2);
if (!(result = (char *)malloc(sizeof(char) + (len1 + len2 + 1))))
return (0);
ft_memcpy(result, s1, len1);
ft_memcpy(result + len1, s2, len2);
result[len1 + len2] = '\0';
return (result);
}
char *ft_strndup(const char *s, size_t n)
{
char *result;
if (!(result = (char *)malloc(sizeof(char) * (n + 1))))
return (0);
ft_memcpy(result, s, n);
result[n] = '\0';
return (result);
}
char *ft_strchr(const char *s, int c)
{
while (*s != c)
{
if (*s == '\0')
return (0);
s++;
}
return (char *)s;
}