Debian Codegraph @

modules/lsp-common-lib/include/lsp-plug.in/stdlib/string.h

raw
1 /*
2 * Copyright (C) 2026 Linux Studio Plugins Project <https://lsp-plug.in/>
3 * (C) 2026 Vladimir Sadovnikov <[email protected]>
4 *
5 * This file is part of lsp-common-lib
6 * Created on: 2 апр. 2020 г.
7 *
8 * lsp-common-lib is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version.
12 *
13 * lsp-common-lib is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with lsp-common-lib. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22 #ifndef LSP_PLUG_IN_STDLIB_STRING_H_
23 #define LSP_PLUG_IN_STDLIB_STRING_H_
24
25 #include <lsp-plug.in/common/version.h>
26 #include <lsp-plug.in/common/types.h>
27
28 #include <string.h>
29 #include <strings.h>
30 #include <stdlib.h>
31
32 #if defined(PLATFORM_WINDOWS)
33 inline char *stpcpy(char *dst, const char *src)
34 {
35 size_t len = ::strlen(src);
36 ::memcpy(dst, src, len + 1);
37 return &dst[len];
38 }
39
40 inline void bzero(void *dst, size_t count)
41 {
42 ::memset(dst, 0, count);
43 }
44
45 inline char *strndup(const char *src, size_t clen)
46 {
47 size_t nlen = ::strnlen(src, clen);
48 char *ptr = reinterpret_cast<char *>(::malloc(nlen + 1));
49 if (ptr != NULL)
50 {
51 ::memcpy(ptr, src, nlen);
52 ptr[nlen] = '\0';
53 }
54
55 return ptr;
56 }
57 #endif /* PLATFORM_WINDOWS */
58
59 namespace lsp
60 {
61 inline void *memdup(const void *src, size_t count)
62 {
63 void *dst = ::malloc(count);
64 if ((dst != NULL) && (count > 0))
65 ::memcpy(dst, src, count);
66 return dst;
67 }
68
69 inline char *strend(char *str)
70 {
71 return &str[strlen(str)];
72 }
73
74 inline const char *strend(const char *str)
75 {
76 return &str[strlen(str)];
77 }
78
79 inline char *strmemdup(const void *src, size_t count)
80 {
81 char *dst = static_cast<char *>(::malloc(count + 1));
82 if (dst != NULL)
83 {
84 ::memcpy(dst, src, count);
85 dst[count] = '\0';
86 }
87 return dst;
88 }
89 } /* namespace lsp */
90
91 #endif /* LSP_PLUG_IN_STDLIB_STRING_H_ */