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