xref: /csrg-svn/usr.bin/f77/libU77/perror_.c (revision 2522)
1*2522Sdlw /*
2*2522Sdlw char id_perror[] = "@(#)perror_.c	1.1";
3*2522Sdlw  *
4*2522Sdlw  * write a standard error message to the standard error output
5*2522Sdlw  *
6*2522Sdlw  * calling sequence:
7*2522Sdlw  *	call perror(string)
8*2522Sdlw  * where:
9*2522Sdlw  *	string will be written preceeding the standard error message
10*2522Sdlw  */
11*2522Sdlw 
12*2522Sdlw #include	<stdio.h>
13*2522Sdlw #include	"../libI77/fiodefs.h"
14*2522Sdlw #include	"../libI77/f_errno.h"
15*2522Sdlw 
16*2522Sdlw extern char *sys_errlist[];
17*2522Sdlw extern int sys_nerr;
18*2522Sdlw extern char *f_errlist[];
19*2522Sdlw extern int f_nerr;
20*2522Sdlw extern unit units[];
21*2522Sdlw 
22*2522Sdlw perror_(s, len)
23*2522Sdlw char *s; long len;
24*2522Sdlw {
25*2522Sdlw 	char buf[40];
26*2522Sdlw 	char *mesg = s + len;
27*2522Sdlw 
28*2522Sdlw 	while (len > 0 && *--mesg == ' ')
29*2522Sdlw 		len--;
30*2522Sdlw 	if (errno >=0 && errno < sys_nerr)
31*2522Sdlw 		mesg = sys_errlist[errno];
32*2522Sdlw 	else if (errno >= F_ER && errno < (F_ER + f_nerr))
33*2522Sdlw 		mesg = f_errlist[errno - F_ER];
34*2522Sdlw 	else
35*2522Sdlw 	{
36*2522Sdlw 		sprintf(buf, "%d: unknown error number", errno);
37*2522Sdlw 		mesg = buf;
38*2522Sdlw 	}
39*2522Sdlw 	while (len-- > 0)
40*2522Sdlw 		putc(*s++, units[STDERR].ufd);
41*2522Sdlw 	fprintf(units[STDERR].ufd, ": %s\n", mesg);
42*2522Sdlw }
43