Lely core libraries 1.9.2
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
31char *
32strdup(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
45char *
46strndup(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
61size_t
62strnlen(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
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....