-
-/*
- * vfgets.c -- virtual fgets
+/* vfgets.c -- virtual fgets
*
- * $Id$
+ * This code is Copyright (c) 2002, by the authors of nmh. See the
+ * COPYRIGHT file in the root directory of the nmh distribution for
+ * complete copyright information.
*/
#include <h/mh.h>
+#include <h/utils.h>
#define QUOTE '\\'
static char *pp = NULL;
if (pp == NULL)
- if (!(pp = malloc ((size_t) (len = BUFSIZ))))
- adios (NULL, "unable to allocate string storage");
+ pp = mh_xmalloc ((size_t) (len = BUFSIZ));
for (ep = (cp = pp) + len - 1;;) {
if (fgets (cp, ep - cp + 1, in) == NULL) {
if (*dp == '\n') {
*bp = pp;
return 0;
- } else {
- cp = ++dp;
}
+ cp = ++dp;
} else {
for (fp = dp - 1, toggle = 0; fp >= cp; fp--) {
if (*fp != QUOTE)
if (cp >= ep) {
int curlen = cp - pp;
- if (!(dp = realloc (pp, (size_t) (len += BUFSIZ)))) {
- adios (NULL, "unable to allocate string storage");
- } else {
- cp = dp + curlen;
- ep = (pp = dp) + len - 1;
- }
+ dp = mh_xrealloc (pp, (size_t) (len += BUFSIZ));
+ cp = dp + curlen;
+ ep = (pp = dp) + len - 1;
}
}
}