xref: /original-bsd/usr.bin/f77/libU77/getc_.c (revision 1f3a482a)
1 /*
2 char id_getc[] = "@(#)getc_.c	1.2";
3  *
4  * get a character from the standard input
5  *
6  * calling sequence:
7  *	integer getc
8  *	ierror = getc (char)
9  * where:
10  *	char will be read from the standard input, usually the terminal
11  *	ierror will be 0 if successful; a system error code otherwise.
12  */
13 
14 #include	"../libI77/f_errno.h"
15 #include	"../libI77/fiodefs.h"
16 
17 extern unit units[];	/* logical units table from iolib */
18 
19 long getc_(c, clen)
20 char *c; long clen;
21 {
22 	int	i;
23 	unit	*lu;
24 
25 	lu = &units[STDIN];
26 	if (!lu->ufd)
27 		return((long)(errno=F_ERNOPEN));
28 	if (lu->uwrt)
29 		nowreading(lu);
30 	if ((i = getc (lu->ufd)) < 0)
31 	{
32 		if (feof(lu->ufd))
33 			return(-1L);
34 		i = errno;
35 		clearerr(lu->ufd);
36 		return((long)i);
37 	}
38 	*c = i & 0177;
39 	return(0L);
40 }
41