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