Commit 625c2460af7dc17ed4fccb1ab23f0e8e6e8ca85e

Steffen Jaeckel 2019-05-12T23:45:23

Merge pull request #257 from libtom/use-fwrite use fwrite instead of fputc

diff --git a/bn_mp_fwrite.c b/bn_mp_fwrite.c
index 1904237..89ab29f 100644
--- a/bn_mp_fwrite.c
+++ b/bn_mp_fwrite.c
@@ -7,7 +7,7 @@
 int mp_fwrite(const mp_int *a, int radix, FILE *stream)
 {
    char *buf;
-   int err, len, x;
+   int err, len;
 
    if ((err = mp_radix_size(a, radix, &len)) != MP_OKAY) {
       return err;
@@ -23,11 +23,9 @@ int mp_fwrite(const mp_int *a, int radix, FILE *stream)
       return err;
    }
 
-   for (x = 0; x < len; x++) {
-      if (fputc((int)buf[x], stream) == EOF) {
-         MP_FREE_BUFFER(buf, (size_t)len);
-         return MP_VAL;
-      }
+   if (fwrite(buf, (size_t)len, 1, stream) != 1) {
+      MP_FREE_BUFFER(buf, (size_t)len);
+      return MP_ERR;
    }
 
    MP_FREE_BUFFER(buf, (size_t)len);