1 /*
2 Copyright (C) 2007, David Howden.
3 Copyright (C) 2010 William Hart
4
5 This file is part of FLINT.
6
7 FLINT is free software: you can redistribute it and/or modify it under
8 the terms of the GNU Lesser General Public License (LGPL) as published
9 by the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version. See <http://www.gnu.org/licenses/>.
11 */
12
13 #include <gmp.h>
14 #include <stdio.h>
15 #include "flint.h"
16 #include "fmpz_mod_poly.h"
17 #include "fmpz.h"
18
fmpz_mod_poly_fread(FILE * f,fmpz_mod_poly_t poly)19 int fmpz_mod_poly_fread(FILE * f, fmpz_mod_poly_t poly)
20 {
21 slong i, length;
22 fmpz_t coeff;
23 ulong res;
24
25 fmpz_init(coeff);
26 if (flint_fscanf(f, "%wd", &length) != 1) {
27 fmpz_clear(coeff);
28 return 0;
29 }
30
31 fmpz_fread(f,coeff);
32 fmpz_mod_poly_clear(poly);
33 fmpz_mod_poly_init(poly, coeff);
34 fmpz_mod_poly_fit_length(poly, length);
35 poly->length = length;
36
37 for (i = 0; i < length; i++)
38 {
39 res = fmpz_fread(f, coeff);
40 fmpz_mod_poly_set_coeff_fmpz(poly,i,coeff);
41
42 if (!res)
43 {
44 poly->length = i;
45 fmpz_clear(coeff);
46 return 0;
47 }
48 }
49
50 fmpz_clear(coeff);
51 _fmpz_mod_poly_normalise(poly);
52
53 return 1;
54 }
55
56