-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.c
80 lines (73 loc) · 1.6 KB
/
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
72
73
74
75
76
77
78
79
80
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hardy <hardy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/27 18:39:39 by hjimenez #+# #+# */
/* Updated: 2022/05/18 22:19:39 by hardy ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
void
*ft_calloc(size_t nmemb, size_t size)
{
char *pointer;
size_t nbytes;
size_t i;
i = 0;
nbytes = size * nmemb;
pointer = malloc(nbytes);
if (!pointer)
return (NULL);
while (i < nbytes)
{
*(pointer + i) = (char) '\0';
i++;
}
return (pointer);
}
int
send_singal(int type, int pid)
{
int lock;
lock = 1;
usleep(200);
if (type == 1)
{
while (lock)
{
if (!kill(pid, SIGUSR2))
{
lock = 0;
}
}
}
else
{
while (lock)
{
if (!kill(pid, SIGUSR1))
{
lock = 0;
}
}
}
return (1);
}
void ft_write(char *string)
{
int i;
i = 0;
if (!string)
return ;
while (string[i])
{
write(1, &string[i], 1);
++i;
}
write(1, "\n", 1);
fflush(stdout);
usleep(400);
}