-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_next_line_utils_bonus.c
94 lines (84 loc) · 2.46 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gusda-si <gusda-si@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/19 12:43:55 by gusda-si #+# #+# */
/* Updated: 2023/07/23 21:08:16 by gusda-si ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line_bonus.h"
/**
* @brief This functions founds an c character in a string.
*
* @param s The string to search
* @param c The char to search for in the string
* @return Returns a pointer to the character if found.
* @return Returns NULL if not found.
* @return If c == '\0' returns a pointer to the end of the string.
*/
char *ft_strchr(const char *str, int c)
{
while (*str != '\0')
{
if (*str == (unsigned char)c)
return ((char *)str);
str++;
}
if (*str == (unsigned char)c)
return ((char *)str);
return (NULL);
}
char *ft_strjoin(char const *s1, char const *s2)
{
char *new_str;
size_t len;
if (!s1 && !s2)
return (NULL);
len = ft_strlen(s1) + ft_strlen(s2);
new_str = (char *)malloc((len + NULL_BYTE) * sizeof(char));
if (!new_str)
return (NULL);
while (s1 && *s1 != '\0')
*new_str++ = *s1++;
while (s2 && *s2 != '\0')
*new_str++ = *s2++;
*new_str = '\0';
return ((new_str - len));
}
size_t ft_strlen(const char *s)
{
char *s_begin;
if (!s)
return (0);
s_begin = (char *)s;
while (*s != '\0')
s++;
return ((size_t)(s - s_begin));
}
size_t ft_strlcpy(char *dst, const char *src, size_t size)
{
size_t str_len;
str_len = ft_strlen(src);
if ((size <= 0) | !dst)
return (str_len);
while (*src != '\0' && size-- > 1)
*dst++ = *src++;
*dst = '\0';
return (str_len);
}
char *ft_strdup(const char *s)
{
char *new_str;
size_t size;
size = ft_strlen(s);
new_str = (char *)malloc((size + NULL_BYTE) * sizeof(char));
if (new_str == NULL)
return (NULL);
while (*s != '\0')
*new_str++ = *s++;
*new_str = '\0';
return ((new_str - size));
}