Updated PCI IDs to latest snapshot.
[tangerine.git] / compiler / arossupport / readstring.c
blobb9af029a921e43a3767a7b9f0d71113db8e1f407
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Read one C string from a streamhook
6 Lang: english
7 */
9 #include <proto/dos.h>
10 #include <exec/memory.h>
11 #include <proto/exec.h>
13 /******************************************************************************
15 NAME */
16 #include <stdio.h>
17 #include <string.h>
18 #include <aros/bigendianio.h>
19 #include <proto/alib.h>
21 BOOL ReadString (
23 /* SYNOPSIS */
24 struct Hook * hook,
25 STRPTR * dataptr,
26 void * stream)
28 /* FUNCTION
29 Reads one C string from a streamhook.
31 INPUTS
32 hook - Streamhook
33 dataptr - Put the data here. If you don't need the string anymore,
34 call FreeVec() to free it.
35 stream - Read from this stream
37 RESULT
38 The function returns TRUE on success. On success, the string
39 read is written into dataptr. On failure, FALSE is returned and the
40 contents of dataptr are not changed. The string must be freed with
41 FreeVec().
43 NOTES
44 This function reads big endian values from a streamhook even on
45 little endian machines.
47 EXAMPLE
49 BUGS
51 SEE ALSO
52 ReadByte(), ReadWord(), ReadLong(), ReadFloat(), ReadDouble(),
53 ReadString(), ReadStruct(), WriteByte(), WriteWord(), WriteLong(),
54 WriteFloat(), WriteDouble(), WriteString(), WriteStruct()
56 HISTORY
57 14.09.93 ada created
59 ******************************************************************************/
61 STRPTR buffer;
62 LONG size, maxsize;
63 LONG c;
65 size = maxsize = 0;
66 buffer = NULL;
68 for (;;)
70 struct BEIOM_Read rd = {BEIO_READ};
71 c = CallHookA (hook, stream, &rd);
73 if (c == EOF)
75 FreeVec (buffer);
76 return FALSE;
79 if (size == maxsize)
81 STRPTR tmp;
83 tmp = AllocVec (maxsize + 16, MEMF_ANY);
85 if (!tmp)
87 FreeVec (buffer);
88 return FALSE;
91 if (buffer)
93 memcpy (tmp, buffer, maxsize);
94 FreeVec (buffer);
97 maxsize += 16;
99 buffer = tmp;
102 buffer[size ++] = c;
104 if (!c)
105 break;
108 *dataptr = buffer;
110 return TRUE;
111 } /* ReadString */