X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=sbr%2Fvfgets.c;h=1ddd99b9b55f3c1d54615bafb7617297554550d0;hp=1a99b7611641ac46f8ae0e868e0d7877133fd2a3;hb=HEAD;hpb=a485ed478abbd599d8c9aab48934e7a26733ecb1 diff --git a/sbr/vfgets.c b/sbr/vfgets.c index 1a99b76..1ddd99b 100644 --- a/sbr/vfgets.c +++ b/sbr/vfgets.c @@ -1,11 +1,12 @@ /* - * vfgets.c -- virtual fgets - * - * 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. - */ +** vfgets.c -- virtual fgets +** +** 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 #include #include @@ -13,7 +14,7 @@ int -vfgets (FILE *in, char **bp) +vfgets(FILE *in, char **bp) { int toggle; char *cp, *dp, *ep, *fp; @@ -21,21 +22,21 @@ vfgets (FILE *in, char **bp) static char *pp = NULL; if (pp == NULL) - pp = mh_xmalloc ((size_t) (len = BUFSIZ)); + pp = mh_xcalloc(len = BUFSIZ, sizeof(char)); for (ep = (cp = pp) + len - 1;;) { - if (fgets (cp, ep - cp + 1, in) == NULL) { + if (fgets(cp, ep - cp + 1, in) == NULL) { if (cp != pp) { *bp = pp; return 0; } - return (ferror (in) && !feof (in) ? -1 : 1); + return (ferror(in) && !feof(in) ? -1 : 1); } - if ((dp = cp + strlen (cp) - 2) < cp || *dp != QUOTE) { + if ((dp = cp + strlen(cp) - 2) < cp || *dp != QUOTE) { wrong_guess: if (cp > ++dp) - adios (NULL, "vfgets() botch -- you lose big"); + adios(EX_SOFTWARE, NULL, "vfgets() botch -- you lose big"); if (*dp == '\n') { *bp = pp; return 0; @@ -63,7 +64,7 @@ wrong_guess: if (cp >= ep) { int curlen = cp - pp; - dp = mh_xrealloc (pp, (size_t) (len += BUFSIZ)); + dp = mh_xrealloc(pp, len += BUFSIZ); cp = dp + curlen; ep = (pp = dp) + len - 1; }