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.
18 /* Read up to (and including) TERMINATING_STRING from FILE and return it.
19 * Return NULL on EOF. */
21 char *fgets_str(FILE *file, const char *terminating_string)
24 const int term_length = strlen(terminating_string);
25 int end_string_offset;
37 /* grow the line buffer as necessary */
38 while (idx > linebufsz - 2) {
39 linebuf = xrealloc(linebuf, linebufsz += 1000);
45 /* Check for terminating string */
46 end_string_offset = idx - term_length;
47 if (end_string_offset > 0
48 && memcmp(&linebuf[end_string_offset], terminating_string, term_length) == 0
54 linebuf = xrealloc(linebuf, idx + 1);