Initial commit
[pal.git] / pal.c
1 #include <assert.h>
2 #include <stdio.h>
3
4 #include "pal.h"
5
6 int pal_read(FILE * in, struct pal * _pal)
7 {
8         size_t elements;
9
10         assert(in != NULL);
11         assert(_pal != NULL);
12
13         elements = fread(_pal, sizeof(struct pal), 1, in);
14
15         if (elements == 0) {
16                 perror("Unable to correctly read input file");
17                 return PAL_READ_ERROR;
18         }
19
20         return PAL_READ_OK;
21 }
22
23 int pal_read_optional(FILE * in, struct pal_optional * opt)
24 {
25         size_t elements;
26
27         assert(in != NULL);
28
29         elements = fread(&opt, sizeof(struct pal_optional), 1, in);
30         if (elements  == 0) {
31                 return PAL_READ_NOOPT;
32         }
33
34         if (ferror(in)) {
35                 return PAL_READ_ERROR;
36         }
37
38         return PAL_READ_OK;
39 }