Lely core libraries
2.2.5
string.c
Go to the documentation of this file.
1
23
#include "
libc.h
"
24
#include <
lely/libc/string.h
>
25
26
#include <
stdlib.h
>
27
28
#if !(_MSC_VER >= 1400) && !(_POSIX_C_SOURCE >= 200809L) \
29
&& !defined(__MINGW32__)
30
31
char
*
32
strdup(
const
char
*s)
33
{
34
size_t
size = strlen(s) + 1;
35
char
*dup = malloc(size);
36
if
(!dup)
37
return
NULL;
38
return
memcpy(dup, s, size);
39
}
40
41
#endif
42
43
#if !(_POSIX_C_SOURCE >= 200809L)
44
45
char
*
46
strndup(
const
char
*s,
size_t
size)
47
{
48
size = strnlen(s, size);
49
char
*dup = malloc(size + 1);
50
if
(!dup)
51
return
NULL;
52
dup[size] =
'\0'
;
53
return
memcpy(dup, s, size);
54
}
55
56
#endif
57
58
#if !(_MSC_VER >= 1400) && !(_POSIX_C_SOURCE >= 200809L) \
59
&& !defined(__MINGW32__)
60
61
size_t
62
strnlen(
const
char
*s,
size_t
maxlen)
63
{
64
size_t
size = 0;
65
while
(size < maxlen && *s++)
66
size++;
67
return
size;
68
}
69
70
#endif
string.h
libc.h
stdlib.h
src
libc
string.c
Generated by
1.8.17