-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.c
More file actions
91 lines (82 loc) · 1.95 KB
/
Copy pathutils.c
File metadata and controls
91 lines (82 loc) · 1.95 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: uviana-a <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/17 19:38:33 by uviana-a #+# #+# */
/* Updated: 2023/08/17 19:38:35 by uviana-a ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
size_t ft_strlen(const char *s)
{
int i;
i = 0;
while (s[i] != '\0')
{
i++;
}
return (i);
}
void ft_putstr_fd(char *s, int fd)
{
write(fd, s, ft_strlen(s));
}
void ft_putnbr(unsigned int pid)
{
if (pid > 9)
ft_putnbr(pid / 10);
write(1, &"0123456789"[pid % 10], 1);
}
char *ft_strjoin_mod(char *s1, char *s2)
{
char *join;
int i;
int j;
i = -1;
if (!s1)
{
s1 = malloc(sizeof(char) * 1);
s1[0] = '\0';
}
join = (char *)malloc(sizeof(char) * (ft_strlen(s1) + ft_strlen(s2) + 1));
if (!join)
return (NULL);
while (s1[++i] != '\0')
join[i] = s1[i];
j = 0;
while (s2[j] != '\0')
join[i++] = s2[j++];
join[i++] = '\0';
free(s1);
return (join);
}
//RESIZE FT_ATOI
int ft_atoi(const char *nptr)
{
int signal;
int number;
signal = 1;
number = 0;
while (*nptr == 32 || (*nptr >= 9 && *nptr <= 13))
{
nptr++;
}
if (*nptr == '+' || *nptr == '-')
{
if (*nptr == '-')
{
signal = signal * (-1);
}
nptr++;
}
while (*nptr >= '0' && *nptr <= '9')
{
number *= 10;
number += *nptr - 48;
nptr++;
}
return (signal * number);
}