Sticky menus now become non-sticky if menu button is held down for
[AROS.git] / tools / MetaMake / io.c
blobd538ffb48b844eaca8b0568d4cf47d5a1c416ff2
1 /* MetaMake - A Make extension
2 Copyright © 1995-2011, 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 <inttypes.h>
24 #include <stdio.h>
25 #include <string.h> /* for strlen() */
26 #ifdef HAVE_NETINET_IN_H
27 # include <netinet/in.h> /* for htonl/ntohl() */
28 #endif
29 #ifdef _WIN32
30 #include "winsock2.h"
31 #endif
33 #include "mem.h"
35 int
36 writestring (FILE * fh, const char * s)
38 uint32_t out;
39 int32_t len;
41 if (s != NULL)
42 len = strlen(s);
43 else
44 len = -1;
46 out = htonl(len);
47 fwrite(&out, sizeof(out), 1, fh);
49 if (!ferror(fh) && len>0)
50 fwrite(s, len, 1, fh);
52 return !ferror(fh);
55 int
56 readstring (FILE * fh, char **strptr)
58 uint32_t in;
59 int32_t len;
61 fread(&in, sizeof(in), 1, fh);
62 if (ferror(fh))
63 return 0;
65 len = ntohl(in);
66 if (len>0)
68 *strptr = xmalloc (len+1);
69 fread (*strptr, len, 1, fh);
70 if (ferror(fh))
72 xfree (*strptr);
73 return 0;
75 (*strptr)[len] = 0;
77 else if (len == 0)
78 *strptr = xstrdup("");
79 else /* len < 0 */
80 *strptr = NULL;
82 return 1;
85 int
86 writeint32 (FILE * fh, int32_t i)
88 uint32_t out;
90 out = htonl(i);
91 fwrite(&out, sizeof(out), 1, fh);
93 return !ferror(fh);
96 int
97 readint32 (FILE * fh, int32_t * iptr)
99 uint32_t in;
101 fread(&in, sizeof(in), 1, fh);
102 if (!ferror(fh))
103 *iptr = ntohl(in);
105 return !ferror(fh);
109 writeuint32 (FILE * fh, uint32_t i)
111 uint32_t out;
113 out = htonl(i);
114 fwrite(&out, sizeof(out), 1, fh);
116 return !ferror(fh);
120 readuint32 (FILE * fh, uint32_t * iptr)
122 uint32_t in;
124 fread(&in, sizeof(in), 1, fh);
125 if (!ferror(fh))
126 *iptr = ntohl(in);
128 return !ferror(fh);