-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_utils.c
executable file
·71 lines (63 loc) · 1.78 KB
/
ft_utils.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abadidi < abadidi@student.1337.ma> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/11 18:28:09 by abadidi #+# #+# */
/* Updated: 2021/12/11 18:28:09 by abadidi ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
static void *ft_memset(void *str, int c, size_t n)
{
unsigned char *dest;
dest = str;
while (n--)
{
*dest = (unsigned char)c;
dest++;
}
return (str);
}
void ft_bzero(void *str, size_t n)
{
ft_memset(str, 0, n);
}
static int ft_memcmp(const void *s1, const void *s2, size_t n)
{
unsigned char *tmp1;
unsigned char *tmp2;
tmp1 = (unsigned char *)s1;
tmp2 = (unsigned char *)s2;
while (n--)
{
if (*tmp1 != *tmp2)
return (*tmp1 - *tmp2);
tmp1++;
tmp2++;
}
return (0);
}
void *ft_memcpy(void *dest, const void *src, size_t n)
{
char *s;
char *d;
size_t i;
if (dest == NULL && src == NULL)
return (dest);
if (dest == src)
return (dest);
if (!ft_memcmp(dest, src, n))
return (dest);
s = (char *)src;
d = (char *)dest;
i = 0;
while (i < n)
{
d[i] = s[i];
i++;
}
return ((void *)d);
}