Start development on BSD 2
[unix-history] / .ref-BSD-1 / portlib / cputc.c
CommitLineData
520d5775
EA
1# include "iodec.h"
2
3/**
4 ** put a single character
5 **/
6
7int f_log 0;
8
9cputc(c, fn)
10char c;
11int fn;
12{
13 register struct fileps *fp;
14 extern int cout;
15
16 if (fn < 0 || fn >= MAXFILES)
17 __error("cputc: illegal file number %d", fn);
18 fp = &__filehdr[fn];
19 if (fp->wrflag == 1)
20 __error("cputc: file %d not open for write", fn);
21 if (fp->wrflag == 0)
22 __makbuf(fn, 1);
23 if (f_log > 0 && fn == cout)
24 cputc(c, f_log);
25 *fp->bptr++ = c;
26 if (++fp->nchars < fp->bsize)
27 return (c);
28 if (fp->wrflag == 3)
29 {
30 seek(fn, 0, 2);
31 fp->wrflag = 2;
32 }
33 if (write(fn, fp->bptr = fp->buff, fp->nchars) < fp->nchars)
34 __error("cputc: write error on %d", fn);
35 fp->nchars = 0;
36 return (c);
37}