File: cfgets.c

package info (click to toggle)
zmailer 2.99.51.52pre3-2
  • links: PTS
  • area: main
  • in suites: potato
  • size: 16,596 kB
  • ctags: 7,422
  • sloc: ansic: 90,470; sh: 3,608; makefile: 2,784; perl: 1,585; python: 115; awk: 22
file content (35 lines) | stat: -rw-r--r-- 539 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
 *  cfgets() -- A routine for Zmailer  libz.a -library.
 *
 *  Count how many chars are stored into the buffer, EOF if
 *  failed...
 *
 *  By Matti Aarnio <mea@utu.fi> on 26-Sep-94
 */

#include "mailer.h"
#include "libz.h"

int cfgets(s, n, stream)
	char *s;
	int n;
	FILE *stream;
{
	register int cnt = 0;

	while (n > 0) {
	  register int c = getc(stream);
	  if (c != EOF) {
	    *s++ = c;
	    ++cnt;
	    --n;
	    if (c == '\n')
	      break;
	  } else {
	    if (cnt == 0)
	      return EOF;
	    break;
	  }
	}
	return cnt;
}