-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathallocation_export.c
114 lines (103 loc) · 2.15 KB
/
allocation_export.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* allocation_export.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: emohamed <emohamed@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/29 10:40:05 by emohamed #+# #+# */
/* Updated: 2023/09/30 02:24:12 by emohamed ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
char *ft_strdup_export(const char *s1)
{
int i;
char *p;
if (!s1)
return (0);
i = 0;
p = malloc(sizeof(char) * ft_strlen(s1) + 1);
if (!p)
return (NULL);
while (s1[i])
{
p[i] = s1[i];
i++;
}
p[i] = '\0';
return (p);
}
int count_s_lenght_export(const char *s, char c)
{
int i;
int j;
i = 0;
j = 0;
while (s[i])
{
while (s[i] && s[i] == c)
i++;
if (s[i])
j++;
while (s[i] && s[i] != c)
i++;
}
return (j);
}
char *allocat_s_export(const char *s, char c)
{
int i;
int len;
char *p;
i = 0;
len = 0;
while (s[len] && s[len] != c)
len++;
p = malloc(sizeof(char) * (len + 1));
if (!p)
return (NULL);
while (i < len)
{
p[i] = s[i];
i++;
}
p[i] = '\0';
return (p);
}
void *ft_calloc_export(size_t count, size_t size)
{
size_t sizee;
void *p;
p = NULL;
sizee = count * size;
p = malloc(sizee);
if (!p)
return (NULL);
ft_bzero(p, sizee);
return (p);
}
char **ft_split_export(char const *s, char c)
{
char **p;
int i;
int j;
i = 0;
j = 0;
p = ft_calloc(sizeof(char *), count_s_lenght_export(s, c) + 1);
if (!p)
return (NULL);
while (s[i])
{
while (s[i] && s[i] == c)
i++;
if (s[i])
{
p[j] = allocat_s_export(&s[i], c);
j++;
}
while (s[i] && s[i] != c)
i++;
}
return (p);
}