1 /* mpz_inp_raw -- Input a mpz_t in raw, but endianess, and wordsize
2 independent format (as output by mpz_out_raw).
4 Copyright (C) 1991, 1993, 1994, 1995 Free Software Foundation, Inc.
6 This file is part of the GNU MP Library.
8 The GNU MP Library is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Library General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or (at your
11 option) any later version.
13 The GNU MP Library is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
16 License for more details.
18 You should have received a copy of the GNU Library General Public License
19 along with the GNU MP Library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
21 MA 02111-1307, USA. */
30 mpz_inp_raw (mpz_ptr x, FILE *stream)
32 mpz_inp_raw (x, stream)
43 mp_size_t in_bytesize;
49 /* Read 4-byte size */
51 for (i = 4 - 1; i >= 0; i--)
54 in_bytesize = (in_bytesize << BITS_PER_CHAR) | c;
57 /* Size is stored as a 32 bit word; sign extend in_bytesize for non-32 bit
59 if (sizeof (mp_size_t) > 4)
60 in_bytesize |= (-(in_bytesize < 0)) << 31;
62 neg_flag = in_bytesize < 0;
63 in_bytesize = ABS (in_bytesize);
64 xsize = (in_bytesize + BYTES_PER_MP_LIMB - 1) / BYTES_PER_MP_LIMB;
69 return 4; /* we've read 4 bytes */
72 if (x->_mp_alloc < xsize)
73 _mpz_realloc (x, xsize);
77 for (i = (in_bytesize - 1) % BYTES_PER_MP_LIMB; i >= 0; i--)
80 x_limb = (x_limb << BITS_PER_CHAR) | c;
82 xp[xsize - 1] = x_limb;
84 for (s = xsize - 2; s >= 0; s--)
87 for (i = BYTES_PER_MP_LIMB - 1; i >= 0; i--)
90 x_limb = (x_limb << BITS_PER_CHAR) | c;
98 MPN_NORMALIZE (xp, xsize);
99 x->_mp_size = neg_flag ? -xsize : xsize;
100 return in_bytesize + 4;