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

/*
 * libc/stdio/_fgetc.c
 * C Standard I/O Library internals.
 * Unbuffered input.
 */

#include <stdio.h>
#include <errno.h>

extern	int	_fputt();

int
_fgetc(fp) register FILE *fp;
{
	register unsigned char s[1];
	register int n, oerrno;

	if (stdout->_pt==&_fputt)	/* special kludge */
		fflush(stdout);
	fp->_cc = 0;
	oerrno = errno;			/* save old errno */
	errno = 0;
	n = EOF;			/* return value in case error */
	switch (read(fileno(fp), s, 1)) {
	case -1:			/* error */
		if (errno != EINTR)
			fp->_ff |= _FERR;
		break;
	case 0:				/* EOF */
		fp->_ff |= _FEOF;
		break;
	default:			/* success */
		n = s[0];
		break;
	}
	if (errno == 0)
		errno = oerrno;		/* preserve errno if no error */
	return n;
}

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

unix.superglobalmegacorp.com

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