-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile.c
More file actions
67 lines (59 loc) · 1.64 KB
/
Copy pathfile.c
File metadata and controls
67 lines (59 loc) · 1.64 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* file.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mamali <mamali@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/11 18:12:43 by mamali #+# #+# */
/* Updated: 2021/10/11 18:24:52 by mamali ### ########.fr */
/* */
/* ************************************************************************** */
#include "philo.h"
int ft_isdigit(int c)
{
if (c >= 48 && c <= 57)
return (1);
return (0);
}
size_t ft_strlen(const char *str)
{
int i;
i = 0;
while (str[i])
i++;
return (i);
}
void log_error(char *msg)
{
write(2, msg, ft_strlen(msg));
}
static int whitespace(char c)
{
if (c == '\n' || c == '\v' || c == '\f' || c == '\t' || c == '\r')
return (1);
if (c == ' ')
return (1);
return (0);
}
long long ft_atoi(const char *str)
{
int i;
int negativity;
unsigned long result;
result = 0;
negativity = 1;
i = 0;
while (whitespace(str[i]))
i++;
if (str[i] == '-')
negativity = -1;
if (str[i] == '+' || str[i] == '-')
i++;
while (str[i] >= 48 && str[i] <= 57)
{
result = result * 10 + (str[i] - 48);
i++;
}
return (result * negativity);
}