-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathradix_extension.c
85 lines (76 loc) · 1.84 KB
/
radix_extension.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* radix_extension.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rda-cost <rda-cost@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/06/02 17:56:20 by rda-cost #+# #+# */
/* Updated: 2015/06/03 13:51:39 by rda-cost ### ########.fr */
/* */
/* ************************************************************************** */
#include "radix.h"
char *strjoin(char const *s1, char const *s2)
{
char *r;
size_t i;
size_t j;
i = strlen(s1) + strlen(s2);
if (!(r = malloc(sizeof(*r) * (i + 1))))
return (NULL);
i = 0;
while (s1 && s1[i])
{
r[i] = s1[i];
i++;
}
j = 0;
while (s2 && s2[j])
r[i++] = s2[j++];
r[i] = 0;
return (r);
}
int min_strncmp(char *s1, char *s2, unsigned int *out)
{
unsigned int sz1;
unsigned int sz2;
sz1 = strlen(s1);
sz2 = strlen(s2);
if (sz1 > sz2)
{
if (out)
*out = sz2;
return (strncmp(s1, s2, sz2));
}
else
{
if (out)
*out = sz1;
return (strncmp(s1, s2, sz1));
}
}
char *join_free(char *start, char *rec)
{
char *ret;
if (!rec)
{
return (NULL);
}
if (!start)
return (strdup(rec));
ret = strjoin(start, rec);
free(rec);
return (ret);
}
char *join_safe(char *s1, char *s2)
{
char *ret;
if (!s1 && !s2)
return (NULL);
if (!s1)
return (strdup(s2));
if (!s2)
return (strdup(s1));
ret = strjoin(s1, s2);
return (ret);
}