added test for return val of nowreading(). DLW
[unix-history] / usr / src / usr.bin / f77 / libU77 / fgetc_.c
CommitLineData
320df512 1/*
337a7375 2char id_fgetc[] = "@(#)fgetc_.c 1.4";
320df512
DW
3 *
4 * get a character from a logical unit bypassing formatted I/O
5 *
6 * calling sequence:
7 * integer fgetc
8 * ierror = fgetc (unit, char)
9 * where:
10 * char will return a character from logical unit
11 * ierror will be 0 if successful; a system error code otherwise.
12 */
13
14#include "../libI77/fiodefs.h"
15#include "../libI77/f_errno.h"
16
17extern unit units[]; /* logical units table from iolib */
18
19long fgetc_(u, c, clen)
20long *u; char *c; long clen;
21{
338a6799
DW
22 int i;
23 unit *lu;
320df512
DW
24
25 if (*u < 0 || *u >= MXUNIT)
abb67f25 26 return((long)(errno=F_ERUNIT));
338a6799
DW
27 lu = &units[*u];
28 if (!lu->ufd)
320df512 29 return((long)(errno=F_ERNOPEN));
337a7375
DW
30 if (lu->uwrt && ! nowreading(lu))
31 return((long)errno);
338a6799 32 if ((i = getc (lu->ufd)) < 0)
320df512 33 {
338a6799 34 if (feof(lu->ufd))
320df512
DW
35 return(-1L);
36 i = errno;
338a6799 37 clearerr(lu->ufd);
320df512
DW
38 return((long)i);
39 }
40 *c = i & 0177;
41 return(0L);
42}