3 * vfgets.c -- virtual fgets
7 * This code is Copyright (c) 2002, by the authors of nmh. See the
8 * COPYRIGHT file in the root directory of the nmh distribution for
9 * complete copyright information.
18 vfgets (FILE *in, char **bp)
21 char *cp, *dp, *ep, *fp;
23 static char *pp = NULL;
26 if (!(pp = malloc ((size_t) (len = BUFSIZ))))
27 adios (NULL, "unable to allocate string storage");
29 for (ep = (cp = pp) + len - 1;;) {
30 if (fgets (cp, ep - cp + 1, in) == NULL) {
35 return (ferror (in) && !feof (in) ? -1 : 1);
38 if ((dp = cp + strlen (cp) - 2) < cp || *dp != QUOTE) {
41 adios (NULL, "vfgets() botch -- you lose big");
49 for (fp = dp - 1, toggle = 0; fp >= cp; fp--) {
69 if (!(dp = realloc (pp, (size_t) (len += BUFSIZ)))) {
70 adios (NULL, "unable to allocate string storage");
73 ep = (pp = dp) + len - 1;