File:  [MW Coherent from dump] / coherent / b / lib / libc / stdio / fgets.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Wed May 29 04:56:35 2019 UTC (7 years ago) by root
Branches: MarkWilliams, MAIN
CVS tags: relic, HEAD
coherent

/*
 * libc/stdio/fgets.c
 * ANSI-compliant C standard i/o library.
 * fgets()
 * ANSI 4.9.10.2.
 * Get string from stream.
 * Read up to n-1 characters, including newline.
 */

#include <stdio.h>

char *
fgets(s, n, stream) char *s; register int n; FILE *stream;
{
	register c;
	register char *cp;

	cp = s;
	while (--n > 0 && (c = getc(stream)) != EOF)
		if ((*cp++ = c) == '\n')
			break;
	if (c == EOF && (cp == s || ferror(stream)))
		return NULL;		/* ANSI says leave *cp unchanged */
	*cp = '\0';			/* else NUL-terminate */
	return s;
}

/* end of libc/stdio/fgets.c */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.