diff options
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 |
3 files changed, 15 insertions, 5 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 |
