1 /*- 2 * Copyright (c) 1980 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.proprietary.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)fgetc_.c 5.2 (Berkeley) 04/12/91"; 10 #endif /* not lint */ 11 12 /* 13 * get a character from a logical unit bypassing formatted I/O 14 * 15 * calling sequence: 16 * integer fgetc 17 * ierror = fgetc (unit, char) 18 * where: 19 * char will return a character from logical unit 20 * ierror will be 0 if successful; a system error code otherwise. 21 */ 22 23 #include "../libI77/fiodefs.h" 24 #include "../libI77/f_errno.h" 25 26 extern unit units[]; /* logical units table from iolib */ 27 28 long fgetc_(u, c, clen) 29 long *u; char *c; long clen; 30 { 31 int i; 32 unit *lu; 33 34 if (*u < 0 || *u >= MXUNIT) 35 return((long)(errno=F_ERUNIT)); 36 lu = &units[*u]; 37 if (!lu->ufd) 38 return((long)(errno=F_ERNOPEN)); 39 if (lu->uwrt && ! nowreading(lu)) 40 return((long)errno); 41 if ((i = getc (lu->ufd)) < 0) 42 { 43 if (feof(lu->ufd)) 44 return(-1L); 45 i = errno; 46 clearerr(lu->ufd); 47 return((long)i); 48 } 49 *c = i; 50 return(0L); 51 } 52