From 5c2710cf8146df4132f41b3d5061307e73f13a0c Mon Sep 17 00:00:00 2001 From: Torbjorn Granlund Date: Thu, 19 Nov 2020 13:53:01 +0100 Subject: Use local str_casecmp instead of non-standard strcasecmp. --- tests/mpz/convert.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/mpz/convert.c b/tests/mpz/convert.c index 82a879797..c449c669e 100644 --- a/tests/mpz/convert.c +++ b/tests/mpz/convert.c @@ -21,12 +21,14 @@ the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */ #include #include #include /* for strlen */ +#include /* for tolower */ #include "gmp-impl.h" #include "tests.h" void debug_mp (mpz_t, int); +static int str_casecmp (const char *, const char *); void string_urandomb (char *bp, size_t len, int base, gmp_randstate_ptr rands) @@ -140,7 +142,7 @@ main (int argc, char **argv) for (bp = buf; bp[0] == '0' && bp[1] != '\0'; bp++) ; - if (strcasecmp (str, bp) != 0) + if (str_casecmp (str, bp) != 0) { fprintf (stderr, "ERROR, str and buf different in test %d\n", i); fprintf (stderr, "str = %s\n", str); @@ -162,6 +164,21 @@ main (int argc, char **argv) exit (0); } +/* This is similar to POSIX strcasecmp except that we don't do the comparison + with unsigned char. We avoid strcasecmp for C standard conformance. */ +static int +str_casecmp (const char *s1, const char *s2) +{ + size_t i; + for (i = 0;; i++) + { + int c1 = s1[i]; + int c2 = s2[i]; + if (c1 == 0 || tolower (c1) != tolower (c2)) + return c1 - c2; + } +} + void debug_mp (mpz_t x, int base) { -- cgit v1.2.1