]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
gmputil: turn mpz_printf into mpz_vfprintf to restore --with-mini-gmp
authorPablo Neira Ayuso <pablo@netfilter.org>
Wed, 22 Nov 2017 19:21:04 +0000 (20:21 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Wed, 22 Nov 2017 19:38:11 +0000 (20:38 +0100)
2535ba7006f2 ("src: get rid of printf") uses gmp_vfprintf() which
doesn't exists in mini-gmp.c, this breaks compilation with --mini-gmp.

This patch implements poor man's gmp_vfprintf that takes one single
argument which is what we need.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
include/gmputil.h
src/gmputil.c

index 9c372216cc5281d610399c2555af191a3a57928e..084aa62266879d33e7781b18bf1c59b35a003251 100644 (file)
@@ -7,9 +7,10 @@
 #include <gmp.h>
 #else
 #include <mini-gmp.h>
-/* mini-gmp doesn't come with gmp_printf, so we use our own minimal variant */
-extern int mpz_printf(const char *format, const mpz_t value);
-#define gmp_printf mpz_printf
+#include <stdio.h>
+/* mini-gmp doesn't come with gmp_vfprintf, so we use our own minimal variant */
+extern int mpz_vfprintf(FILE *fp, const char *format, va_list args);
+#define gmp_vfprintf mpz_vfprintf
 #endif
 
 #include <asm/byteorder.h>
index 3cc4e61f546391cb5915e59325fbb6d5346070f5..a25f42ee2b64853f48e137b763a74ed2c9c3e56c 100644 (file)
@@ -145,12 +145,14 @@ void mpz_switch_byteorder(mpz_t rop, unsigned int len)
 /* mini-gmp doesn't have a gmp_printf so we use our own minimal
  * variant here which is able to format a single mpz_t.
  */
-int mpz_printf(const char *f, const mpz_t value)
+int mpz_vfprintf(FILE *fp, const char *f, va_list args)
 {
+       const mpz_t *value = va_arg(args, const mpz_t *);
        int n = 0;
+
        while (*f) {
                if (*f != '%') {
-                       if (fputc(*f, stdout) != *f)
+                       if (fputc(*f, fp) != *f)
                                return -1;
 
                        ++n;
@@ -174,16 +176,16 @@ int mpz_printf(const char *f, const mpz_t value)
                        else
                                return -1;
 
-                       len = mpz_sizeinbase(value, base);
+                       len = mpz_sizeinbase(*value, base);
                        while (prec-- > len) {
-                               if (fputc('0', stdout) != '0')
+                               if (fputc('0', fp) != '0')
                                        return -1;
 
                                ++n;
                        }
 
-                       str = mpz_get_str(NULL, base, value);
-                       ok = str && fwrite(str, 1, len, stdout) == len;
+                       str = mpz_get_str(NULL, base, *value);
+                       ok = str && fwrite(str, 1, len, fp) == len;
                        free(str);
 
                        if (!ok)