1 /* vi: set sw=4 ts=4: */
5 * Copyright (C) many different people.
6 * If you wrote this, please acknowledge your work.
8 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
13 /* Read up to (and including) TERMINATING_STRING from FILE and return it.
14 * Return NULL on EOF. */
16 char *xmalloc_fgets_str(FILE *file, const char *terminating_string)
19 const int term_length = strlen(terminating_string);
20 int end_string_offset;
32 /* grow the line buffer as necessary */
33 while (idx > linebufsz - 2) {
35 linebuf = xrealloc(linebuf, linebufsz);
41 /* Check for terminating string */
42 end_string_offset = idx - term_length;
43 if (end_string_offset > 0
44 && memcmp(&linebuf[end_string_offset], terminating_string, term_length) == 0
50 linebuf = xrealloc(linebuf, idx + 1);