xref: /csrg-svn/usr.bin/f77/libU77/perror_.c (revision 47944)
1*47944Sbostic /*-
2*47944Sbostic  * Copyright (c) 1980 The Regents of the University of California.
3*47944Sbostic  * All rights reserved.
42522Sdlw  *
5*47944Sbostic  * %sccs.include.proprietary.c%
623042Skre  */
723042Skre 
8*47944Sbostic #ifndef lint
9*47944Sbostic static char sccsid[] = "@(#)perror_.c	5.3 (Berkeley) 04/12/91";
10*47944Sbostic #endif /* not lint */
11*47944Sbostic 
1223042Skre /*
132522Sdlw  * write a standard error message to the standard error output
142522Sdlw  *
152522Sdlw  * calling sequence:
162522Sdlw  *	call perror(string)
172522Sdlw  * where:
182522Sdlw  *	string will be written preceeding the standard error message
192522Sdlw  */
202522Sdlw 
212522Sdlw #include	<stdio.h>
222522Sdlw #include	"../libI77/fiodefs.h"
232522Sdlw #include	"../libI77/f_errno.h"
242522Sdlw 
252522Sdlw extern int sys_nerr;
262522Sdlw extern char *f_errlist[];
272522Sdlw extern int f_nerr;
282522Sdlw extern unit units[];
292522Sdlw 
perror_(s,len)302522Sdlw perror_(s, len)
312522Sdlw char *s; long len;
322522Sdlw {
333892Sdlw 	unit	*lu;
343892Sdlw 	char	buf[40];
353892Sdlw 	char	*mesg = s + len;
3642409Sbostic 	char	*strerror();
372522Sdlw 
382522Sdlw 	while (len > 0 && *--mesg == ' ')
392522Sdlw 		len--;
402522Sdlw 	if (errno >=0 && errno < sys_nerr)
4142409Sbostic 		mesg = strerror(errno);
422522Sdlw 	else if (errno >= F_ER && errno < (F_ER + f_nerr))
432522Sdlw 		mesg = f_errlist[errno - F_ER];
442522Sdlw 	else
452522Sdlw 	{
462522Sdlw 		sprintf(buf, "%d: unknown error number", errno);
472522Sdlw 		mesg = buf;
482522Sdlw 	}
493892Sdlw 	lu = &units[STDERR];
503892Sdlw 	if (!lu->uwrt)
513892Sdlw 		nowwriting(lu);
522522Sdlw 	while (len-- > 0)
533892Sdlw 		putc(*s++, lu->ufd);
543892Sdlw 	fprintf(lu->ufd, ": %s\n", mesg);
552522Sdlw }
56