summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2017-11-22 20:21:04 +0100
committerPablo Neira Ayuso <pablo@netfilter.org>2017-11-22 20:38:11 +0100
commit932847e0c3df8f6ee3dc4478f1ef0728926d9544 (patch)
tree6225de85adc157ff7fdc1731901b60cfd400bafa /src
parent9a74945c626290cf8a394436f45da2b3e69401b6 (diff)
gmputil: turn mpz_printf into mpz_vfprintf to restore --with-mini-gmp
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>
Diffstat (limited to 'src')
-rw-r--r--src/gmputil.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/gmputil.c b/src/gmputil.c
index 3cc4e61f..a25f42ee 100644
--- a/src/gmputil.c
+++ b/src/gmputil.c
@@ -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)