From 40e5a5811c6ffce9b0974e93cdd927cbcf60c157 Mon Sep 17 00:00:00 2001 From: Joe Hunkeler Date: Tue, 11 Aug 2015 16:51:37 -0400 Subject: Repatch (from linux) of OSX IRAF --- sys/libc/cflsbuf.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 sys/libc/cflsbuf.c (limited to 'sys/libc/cflsbuf.c') diff --git a/sys/libc/cflsbuf.c b/sys/libc/cflsbuf.c new file mode 100644 index 00000000..9547b0c2 --- /dev/null +++ b/sys/libc/cflsbuf.c @@ -0,0 +1,43 @@ +/* Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. +*/ + +#define import_spp +#define import_libc +#define import_xnames +#define import_stdio +#include + + +/* C_FLSBUF -- Flush the FIO file buffer. Called by the PUTC macro to flush +** the file buffer when it fills. The function value returned is either the +** first char written to the buffer (passed as an argument) or EOF in the +** event of an error. +*/ +int +c_flsbuf ( + unsigned int ch, /* char which caused the fault */ + FILE *fp /* output file */ +) +{ + register int buf_not_full; + XINT fd = fileno(fp); + XINT nreserve = 1; + + + /* If we were called due to flush on newline and there is space in + * the buffer, put the ch in the buffer before flushing. + */ + buf_not_full = (fp->_iop < fp->_otop); + if (buf_not_full) + Memc[fp->_iop++] = (unsigned)ch; + + iferr (FLSBUF (&fd, &nreserve)) { + fp->_fflags |= _FERR; + return (EOF); + } + + if (!buf_not_full) + Memc[fp->_iop++] = (unsigned)ch; + + return (ch); +} -- cgit