1 /* vim: set expandtab ts=4 sw=4: */
2 /*
3 * You may redistribute this program and/or modify it under the terms of
4 * the GNU General Public License as published by the Free Software Foundation,
5 * either version 3 of the License, or (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <https://www.gnu.org/licenses/>.
14 */
15 #include "util/CString.h"
16 #include "util/Bits.h"
17
18 #include <string.h>
19
20 #if defined(Illumos) || defined(__sun)
21 #define _XPG4_2
22 #endif
23 #include <strings.h>
24
CString_strlen(const char * str)25 unsigned long CString_strlen(const char* str)
26 {
27 return strlen(str);
28 }
29
CString_strcmp(const char * a,const char * b)30 int CString_strcmp(const char* a, const char* b)
31 {
32 return strcmp(a,b);
33 }
34
CString_strncmp(const char * a,const char * b,size_t n)35 int CString_strncmp(const char* a, const char *b, size_t n)
36 {
37 return strncmp(a, b, n);
38 }
39
CString_strchr(const char * a,int b)40 char* CString_strchr(const char* a, int b)
41 {
42 return strchr(a,b);
43 }
44
CString_strrchr(const char * a,int b)45 char* CString_strrchr(const char* a, int b)
46 {
47 return strrchr(a,b);
48 }
49
CString_strcasecmp(const char * a,const char * b)50 int CString_strcasecmp(const char *a, const char *b)
51 {
52 return strcasecmp(a,b);
53 }
54
CString_strstr(const char * haystack,const char * needle)55 char* CString_strstr(const char* haystack, const char* needle)
56 {
57 return strstr(haystack,needle);
58 }
59
CString_strcpy(char * restrict dest,const char * restrict src)60 char* CString_strcpy(char* restrict dest, const char* restrict src)
61 {
62 return strcpy(dest, src);
63 }
64
CString_safeStrncpy(char * restrict dest,const char * restrict src,size_t n)65 char* CString_safeStrncpy(char* restrict dest, const char *restrict src, size_t n)
66 {
67 char* ret = strncpy(dest, src, n);
68 dest[n - 1] = '\0';
69 return ret;
70 }
71
CString_strdup(const char * string,struct Allocator * alloc)72 char* CString_strdup(const char* string, struct Allocator* alloc)
73 {
74 int len = CString_strlen(string);
75 char* out = Allocator_calloc(alloc, len+1, 1);
76 Bits_memcpy(out, string, len);
77 return out;
78 }