Commit | Line | Data |
---|---|---|
3719602c PC |
1 | /* Copyright (C) 2010-2020 The RetroArch team |
2 | * | |
3 | * --------------------------------------------------------------------------------------- | |
4 | * The following license statement only applies to this file (compat_posix_string.c). | |
5 | * --------------------------------------------------------------------------------------- | |
6 | * | |
7 | * Permission is hereby granted, free of charge, | |
8 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), | |
9 | * to deal in the Software without restriction, including without limitation the rights to | |
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, | |
11 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |
12 | * | |
13 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | |
16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | |
19 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
21 | */ | |
22 | ||
23 | #include <ctype.h> | |
24 | ||
25 | #include <compat/posix_string.h> | |
26 | ||
27 | #ifdef _WIN32 | |
28 | ||
29 | #undef strcasecmp | |
30 | #undef strdup | |
31 | #undef isblank | |
32 | #undef strtok_r | |
33 | #include <ctype.h> | |
34 | #include <stdlib.h> | |
35 | #include <stddef.h> | |
36 | #include <compat/strl.h> | |
37 | ||
38 | #include <string.h> | |
39 | ||
40 | int retro_strcasecmp__(const char *a, const char *b) | |
41 | { | |
42 | while (*a && *b) | |
43 | { | |
44 | int a_ = tolower(*a); | |
45 | int b_ = tolower(*b); | |
46 | ||
47 | if (a_ != b_) | |
48 | return a_ - b_; | |
49 | ||
50 | a++; | |
51 | b++; | |
52 | } | |
53 | ||
54 | return tolower(*a) - tolower(*b); | |
55 | } | |
56 | ||
57 | char *retro_strdup__(const char *orig) | |
58 | { | |
59 | size_t len = strlen(orig) + 1; | |
60 | char *ret = (char*)malloc(len); | |
61 | if (!ret) | |
62 | return NULL; | |
63 | ||
64 | strlcpy(ret, orig, len); | |
65 | return ret; | |
66 | } | |
67 | ||
68 | int retro_isblank__(int c) | |
69 | { | |
70 | return (c == ' ') || (c == '\t'); | |
71 | } | |
72 | ||
73 | char *retro_strtok_r__(char *str, const char *delim, char **saveptr) | |
74 | { | |
75 | char *first = NULL; | |
76 | if (!saveptr || !delim) | |
77 | return NULL; | |
78 | ||
79 | if (str) | |
80 | *saveptr = str; | |
81 | ||
82 | do | |
83 | { | |
84 | char *ptr = NULL; | |
85 | first = *saveptr; | |
86 | while (*first && strchr(delim, *first)) | |
87 | *first++ = '\0'; | |
88 | ||
89 | if (*first == '\0') | |
90 | return NULL; | |
91 | ||
92 | ptr = first + 1; | |
93 | ||
94 | while (*ptr && !strchr(delim, *ptr)) | |
95 | ptr++; | |
96 | ||
97 | *saveptr = ptr + (*ptr ? 1 : 0); | |
98 | *ptr = '\0'; | |
99 | } while (strlen(first) == 0); | |
100 | ||
101 | return first; | |
102 | } | |
103 | ||
104 | #endif |