diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/string/strcmp.c | 7 | ||||
-rw-r--r-- | src/string/strdup.c | 1 | ||||
-rw-r--r-- | src/string/strstr.c | 12 | ||||
-rw-r--r-- | src/string/substring.h | 9 | ||||
-rw-r--r-- | src/wchar/wcscmp.c | 7 | ||||
-rw-r--r-- | src/wchar/wcsstr.c | 12 |
6 files changed, 35 insertions, 13 deletions
diff --git a/src/string/strcmp.c b/src/string/strcmp.c index f626f91..56b4d1b 100644 --- a/src/string/strcmp.c +++ b/src/string/strcmp.c @@ -17,7 +17,7 @@ */ #include <string.h> #include <strings.h> -#include <inttypes.h> +#include <stdint.h> #include <ctype.h> @@ -108,7 +108,7 @@ int strncmp(const char* a, const char* b, size_t length) int strncasecmp(const char* a, const char* b, size_t length) { int c1, c2; - for (; size--; a++, b++) + for (; length--; a++, b++) if (*a != *b) { c1 = isalpha(*a) ? tolower(*a) : (int)*a; @@ -116,6 +116,9 @@ int strncasecmp(const char* a, const char* b, size_t length) if ((c1 -= c2)) return c1; } + else if (!*a && !*b) return 0; + else if (!*a) return -1; + else if (!*b) return +1; return 0; } diff --git a/src/string/strdup.c b/src/string/strdup.c index c23548b..6a66c2c 100644 --- a/src/string/strdup.c +++ b/src/string/strdup.c @@ -16,6 +16,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <string.h> +#include <stdlib.h> diff --git a/src/string/strstr.c b/src/string/strstr.c index 68cc647..0c67153 100644 --- a/src/string/strstr.c +++ b/src/string/strstr.c @@ -16,7 +16,13 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <string.h> -#include <inttypes.h> +#include <stdint.h> +#include <unistd.h> +#include <alloca.h> +#include <ctype.h> + + +# pragma GCC diagnostic ignored "-Wdiscarded-qualifiers" @@ -143,7 +149,7 @@ void* memmem(const void* __haystack, size_t haystack_length, if (haystack_length < needle_length) return NULL; if (haystack_length == needle_length) - return !memcmp(haystack, haystack_length, haystack_length) ? haystack : NULL; + return !memcmp(haystack, needle, haystack_length) ? haystack : NULL; #include "substring.h" } @@ -170,7 +176,7 @@ void* memcasemem(const void* __haystack, size_t haystack_length, if (haystack_length < needle_length) return NULL; if (haystack_length == needle_length) - return !memcasecmp(haystack, haystack_length, haystack_length) ? haystack : NULL; + return !memcasecmp(haystack, needle, haystack_length) ? haystack : NULL; #define CASE #include "substring.h" #undef CASE diff --git a/src/string/substring.h b/src/string/substring.h index 10e4a7d..9d6dbfe 100644 --- a/src/string/substring.h +++ b/src/string/substring.h @@ -47,7 +47,7 @@ ssize_t hay, ned, skp; ned = 0, skp = next_map[0] = -1; - while (ned < needle_length) + while (ned < (ssize_t)needle_length) { while ((skp > -1) && !CHREQ(needle[ned], needle[skp])) skp = next_map[skp]; @@ -56,15 +56,18 @@ } hay = ned = 0; - while (hay < haystack_length) + while (hay < (ssize_t)haystack_length) { while ((ned > -1) && !CHREQ(haystack[hay], needle[ned])) ned = next_map[ned]; hay++, ned++; - if (ned >= needle_length) + if (ned >= (ssize_t)needle_length) return needle + (hay - ned); } return NULL; } + +#undef CHREQ + diff --git a/src/wchar/wcscmp.c b/src/wchar/wcscmp.c index c9d1180..7539458 100644 --- a/src/wchar/wcscmp.c +++ b/src/wchar/wcscmp.c @@ -16,7 +16,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <wchar.h> -#include <inttypes.h> +#include <stdint.h> #include <wctype.h> @@ -111,7 +111,7 @@ int wcsncmp(const wchar_t* a, const wchar_t* b, size_t length) int wcsncasecmp(const wchar_t* a, const wchar_t* b, size_t length) { wchar_t c1, c2; - for (; size--; a++, b++) + for (; length--; a++, b++) if (*a != *b) { c1 = iswalpha(*a) ? towlower(*a) : *a; @@ -119,6 +119,9 @@ int wcsncasecmp(const wchar_t* a, const wchar_t* b, size_t length) if (c1 < c2) return -1; if (c1 > c2) return +1; } + else if (!*a && !*b) return 0; + else if (!*a) return -1; + else if (!*b) return +1; return 0; } diff --git a/src/wchar/wcsstr.c b/src/wchar/wcsstr.c index 0ae7b71..1a4786e 100644 --- a/src/wchar/wcsstr.c +++ b/src/wchar/wcsstr.c @@ -16,11 +16,17 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <wchar.h> -#include <inttypes.h> +#include <stdint.h> +#include <unistd.h> +#include <alloca.h> +#include <wctype.h> #define WIDE +# pragma GCC diagnostic ignored "-Wdiscarded-qualifiers" + + /** * This function is identical to `wcsstr`. @@ -155,7 +161,7 @@ wchar_t* wmemmem(const wchar_t* haystack, size_t haystack_length, if (haystack_length < needle_length) return NULL; if (haystack_length == needle_length) - return !wmemcmp(haystack, haystack_length, haystack_length) ? haystack : NULL; + return !wmemcmp(haystack, needle, haystack_length) ? haystack : NULL; #include "../string/substring.h" } @@ -180,7 +186,7 @@ wchar_t* wmemcasemem(const wchar_t* haystack, size_t haystack_length, if (haystack_length < needle_length) return NULL; if (haystack_length == needle_length) - return !wmemcasecmp(haystack, haystack_length, haystack_length) ? haystack : NULL; + return !wmemcasecmp(haystack, needle, haystack_length) ? haystack : NULL; #define CASE #include "../string/substring.h" #undef CASE |