1 /*
2  * Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/>
3  *           (C) 2020 Vladimir Sadovnikov <sadko4u@gmail.com>
4  *
5  * This file is part of lsp-plugins
6  * Created on: 15 февр. 2019 г.
7  *
8  * lsp-plugins 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-plugins 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-plugins. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef CORE_STDLIB_STRING_H_
23 #define CORE_STDLIB_STRING_H_
24 
25 #include <common/types.h>
26 #include <string.h>
27 #include <strings.h>
28 #include <stdlib.h>
29 
30 #if defined(PLATFORM_WINDOWS)
stpcpy(char * dst,const char * src)31     inline char *stpcpy(char *dst, const char *src)
32     {
33         size_t len = ::strlen(src);
34         ::memcpy(dst, src, len + 1);
35         return &dst[len];
36     }
37 
bzero(void * dst,size_t count)38     inline void bzero(void *dst, size_t count)
39     {
40         ::memset(dst, 0, count);
41     }
42 
strndup(const char * src,size_t clen)43     inline char *strndup(const char *src, size_t clen)
44     {
45         size_t nlen = ::strnlen(src, clen);
46         char *ptr   = reinterpret_cast<char *>(::malloc(nlen + 1));
47         if (ptr != NULL)
48         {
49             ::memcpy(ptr, src, nlen);
50             ptr[nlen]   = '\0';
51         }
52 
53         return ptr;
54     }
55 #endif /* PLATFORM_WINDOWS */
56 
lsp_memdup(const void * src,size_t count)57     inline void *lsp_memdup(const void *src, size_t count)
58     {
59         void *dst = ::malloc(count);
60         if (count > 0)
61             ::memcpy(dst, src, count);
62         return dst;
63     }
64 
65 #endif /* CORE_STDLIB_STRING_H_ */
66