Blob


1 #include <u.h>
2 #include <libc.h>
3 #include <bio.h>
4 #include "libString.h"
6 /* Append an input line to a String.
7 *
8 * Returns a pointer to the character string (or 0).
9 * Trailing newline is left on.
10 */
11 extern char *
12 s_read_line(Biobuf *fp, String *to)
13 {
14 char *cp;
15 int llen;
17 if(to->ref > 1)
18 sysfatal("can't s_read_line a shared string");
19 s_terminate(to);
20 cp = Brdline(fp, '\n');
21 if(cp == 0)
22 return 0;
23 llen = Blinelen(fp);
24 if(to->end - to->ptr < llen)
25 s_grow(to, llen);
26 memmove(to->ptr, cp, llen);
27 cp = to->ptr;
28 to->ptr += llen;
29 s_terminate(to);
30 return cp;
31 }