2 Copyright (C) 2006 by Jonas Kramer
3 Published under the terms of the GNU General Public License (GPL).
14 Reads a line until EOF or a line break occurs, whatever comes first.
15 The first parameter must be a pointer to another pointer which should either
16 be NULL or point to memory area reserved with *alloc. If it's a pointer to a
17 memory area, that memory will be used and resized as needed. In this case,
18 the second argument must point to an unsigned holding the size of the
19 allocated memory area. Otherwise, the memory will be freshly allocated and
20 it's size will be stored in the unsigned pointed to by the second argument.
21 The third argument is a FILE pointer which the line will be read from.
23 unsigned getln(char ** ptr
, unsigned * size
, FILE * fd
) {
32 while(!feof(fd
) && ch
!= (char) 10) {
38 if(length
+ 2 > * size
) {
39 * ptr
= realloc(* ptr
, (* size
+= 1024));
43 (* ptr
)[length
++] = (char) ch
;
48 * ptr
= realloc(* ptr
, * size
);