-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.c
64 lines (59 loc) · 1.68 KB
/
client.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* client.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: anaouadi <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/04 12:15:03 by anaouadi #+# #+# */
/* Updated: 2022/03/13 14:31:19 by anaouadi ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
t_info g_info;
void handler(int sig)
{
if (g_info.j == 8)
{
g_info.j = 0;
g_info.i++;
}
if (g_info.len == g_info.i)
exit(0);
if (get_bit(g_info.str[g_info.i], g_info.j++) == 0)
{
if (kill(g_info.spid, SIGUSR1) == -1)
g_info.inv = 1;
}
else
{
if (kill(g_info.spid, SIGUSR2) == -1)
g_info.inv = 1;
}
(void)sig;
}
int main(int argc, char **argv)
{
struct sigaction sa;
if (argc < 3)
{
ft_printf("Enter Valid Arguments");
return (0);
}
g_info.spid = ft_atoi(argv[1]);
g_info.len = ft_strlen(argv[2]);
g_info.i = 0;
g_info.j = 0;
g_info.str = (unsigned char *) argv[2];
sa.sa_handler = handler;
sigaction(SIGUSR2, &sa, NULL);
handler(0);
if (g_info.inv == 1)
{
ft_printf("Invalid PID or Empty Text!");
return (0);
}
while (1)
pause();
return (argc);
}