-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidations.c
41 lines (36 loc) · 1.49 KB
/
validations.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* validations.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ansebast <ansebast@student.42luanda.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/05 14:11:00 by ansebast #+# #+# */
/* Updated: 2024/11/21 23:15:35 by ansebast ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
int check_pid(long pid)
{
return (kill(pid, 0));
}
void validate_client_args(int argc, char **argv)
{
int pid;
if (argc != 3)
ft_puterror("Correct usage: ./client <pid_server> <string_to_send>\n",
2);
if (!ft_isint(argv[1]))
ft_puterror("Invalid PID\n", 2);
pid = ft_atol(argv[1]);
if (pid <= 0 || check_pid(pid) != 0)
ft_puterror("This PID does not correspond to any valid process\n", 2);
if (ft_isempty(argv[2]))
ft_puterror("Message cannot be empty\n", 2);
}
void validate_server_args(int argc, char **argv)
{
(void)argv;
if (argc > 1)
ft_puterror("Correct usage: ./server\n", 2);
}