-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils6.c
82 lines (72 loc) · 1.8 KB
/
utils6.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
81
82
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils6.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mazaroua <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/16 13:14:56 by mazaroua #+# #+# */
/* Updated: 2023/05/16 13:17:04 by mazaroua ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
char *ft_strdup_export(char *src)
{
int i;
char *new;
i = 0;
new = malloc(sizeof(char) * ft_strlen(src) + 1);
if (!(new))
return (NULL);
while (*src)
new[i++] = *src++;
new[i] = '\0';
return (new);
}
char *ft_strndup(char *src, int len)
{
int i;
char *new;
if (len == 0)
return (NULL);
i = 0;
new = (char *)ft_malloc(1, ft_strlen(src) + 1);
if (!(new))
return (NULL);
while (*src && i < len)
new[i++] = *src++;
new[i] = '\0';
return (new);
}
char *ft_strndup2(char *src, int len)
{
int i;
char *new;
if (len == 0)
return (NULL);
i = 0;
new = malloc(sizeof(char) * len + 1);
if (!(new))
return (NULL);
while (*src && i < len)
new[i++] = *src++;
new[i] = '\0';
return (new);
}
int ft_isdigit(int c)
{
if (c >= '0' && c <= '9')
return (1);
else
return (0);
}
void free_2d(char **str)
{
int i;
i = 0;
while (str[i])
i++;
while (i > -1)
free(str[i--]);
free(str);
}