summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTorbjorn Granlund <tg@gmplib.org>2020-11-19 13:53:01 +0100
committerTorbjorn Granlund <tg@gmplib.org>2020-11-19 13:53:01 +0100
commit5c2710cf8146df4132f41b3d5061307e73f13a0c (patch)
tree7cbb12e113511737a497efc15292c8043139069a /tests
parentf41a812548f3a7aabca4acbe9c466b61a0c5432c (diff)
downloadgmp-5c2710cf8146df4132f41b3d5061307e73f13a0c.tar.gz
Use local str_casecmp instead of non-standard strcasecmp.
Diffstat (limited to 'tests')
-rw-r--r--tests/mpz/convert.c19
1 files changed, 18 insertions, 1 deletions
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 <stdio.h>
#include <stdlib.h>
#include <string.h> /* for strlen */
+#include <ctype.h> /* 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)
{