diff options
author | Mattias Andrée <maandree@operamail.com> | 2015-09-02 04:44:53 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2015-09-02 04:44:53 +0200 |
commit | bd5d2162efae9913f2666c80bdf944a65ea95590 (patch) | |
tree | 7cfda8110528b22a8377bf9fdf526b9e203beda9 /src/string | |
parent | remove old debug line (diff) | |
download | slibc-bd5d2162efae9913f2666c80bdf944a65ea95590.tar.gz slibc-bd5d2162efae9913f2666c80bdf944a65ea95590.tar.bz2 slibc-bd5d2162efae9913f2666c80bdf944a65ea95590.tar.xz |
fix more errors
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-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 |
4 files changed, 21 insertions, 8 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 + |