Print all of flags register again.
[cake.git] / tools / MetaMake / io.c
blob9a6c5795fefb345d7efcff4e7a4aea60536cffee
1 /* MetaMake - A Make extension
2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
4 This file is part of MetaMake.
6 MetaMake is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 MetaMake is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 #include "config.h"
23 #include <stdio.h>
24 #include <string.h> /* for strlen() */
25 #ifdef HAVE_NETINET_IN_H
26 # include <netinet/in.h> /* for htonl/ntohl() */
27 #endif
29 #include "mem.h"
31 int
32 writestring (FILE * fh, const char * s)
34 uint32_t out;
35 int32_t len;
37 if (s != NULL)
38 len = strlen(s);
39 else
40 len = -1;
42 out = htonl(len);
43 fwrite(&out, sizeof(out), 1, fh);
45 if (!ferror(fh) && len>0)
46 fwrite(s, len, 1, fh);
48 return !ferror(fh);
51 int
52 readstring (FILE * fh, char **strptr)
54 uint32_t in;
55 int32_t len;
57 fread(&in, sizeof(in), 1, fh);
58 if (ferror(fh))
59 return 0;
61 len = ntohl(in);
62 if (len>0)
64 *strptr = xmalloc (len+1);
65 fread (*strptr, len, 1, fh);
66 if (ferror(fh))
68 xfree (*strptr);
69 return 0;
71 (*strptr)[len] = 0;
73 else if (len == 0)
74 *strptr = xstrdup("");
75 else /* len < 0 */
76 *strptr = NULL;
78 return 1;
81 int
82 writeint32 (FILE * fh, int32_t i)
84 uint32_t out;
86 out = htonl(i);
87 fwrite(&out, sizeof(out), 1, fh);
89 return !ferror(fh);
92 int
93 readint32 (FILE * fh, int32_t * iptr)
95 uint32_t in;
97 fread(&in, sizeof(in), 1, fh);
98 if (!ferror(fh))
99 *iptr = ntohl(in);
101 return !ferror(fh);
105 writeuint32 (FILE * fh, uint32_t i)
107 uint32_t out;
109 out = htonl(i);
110 fwrite(&out, sizeof(out), 1, fh);
112 return !ferror(fh);
116 readuint32 (FILE * fh, uint32_t * iptr)
118 uint32_t in;
120 fread(&in, sizeof(in), 1, fh);
121 if (!ferror(fh))
122 *iptr = ntohl(in);
124 return !ferror(fh);