xref: /csrg-svn/usr.bin/f77/libU77/fputc_.c (revision 47944)
1*47944Sbostic /*-
2*47944Sbostic  * Copyright (c) 1980 The Regents of the University of California.
3*47944Sbostic  * All rights reserved.
42409Sdlw  *
5*47944Sbostic  * %sccs.include.proprietary.c%
623014Skre  */
723014Skre 
8*47944Sbostic #ifndef lint
9*47944Sbostic static char sccsid[] = "@(#)fputc_.c	5.2 (Berkeley) 04/12/91";
10*47944Sbostic #endif /* not lint */
11*47944Sbostic 
1223014Skre /*
132409Sdlw  * write a character to a logical unit bypassing formatted I/O
142409Sdlw  *
152409Sdlw  * calling sequence:
162409Sdlw  *	integer fputc
172409Sdlw  *	ierror = fputc (unit, char)
182409Sdlw  * where:
192409Sdlw  *	char will be sent to the logical unit
202409Sdlw  *	ierror will be 0 if successful; a system error code otherwise.
212409Sdlw  */
222409Sdlw 
232409Sdlw #include	"../libI77/fiodefs.h"
242409Sdlw #include	"../libI77/f_errno.h"
252409Sdlw 
262409Sdlw extern unit units[];	/* logical units table from iolib */
272409Sdlw 
fputc_(u,c,clen)282409Sdlw long fputc_(u, c, clen)
292409Sdlw long *u; char *c; long clen;
302409Sdlw {
313893Sdlw 	int	i;
323893Sdlw 	unit	*lu;
332409Sdlw 
342409Sdlw 	if (*u < 0 || *u >= MXUNIT)
352577Sdlw 		return((long)(errno=F_ERUNIT));
363893Sdlw 	lu = &units[*u];
373893Sdlw 	if (!lu->ufd)
382409Sdlw 		return((long)(errno=F_ERNOPEN));
394112Sdlw 	if (!lu->uwrt && ! nowwriting(lu))
404112Sdlw 		return((long)errno);
413893Sdlw 	putc (*c, lu->ufd);
423893Sdlw 	if (ferror(lu->ufd))
432409Sdlw 	{
442409Sdlw 		i = errno;
453893Sdlw 		clearerr(lu->ufd);
462409Sdlw 		return((long)i);
472409Sdlw 	}
482409Sdlw 	return(0L);
492409Sdlw }
50