xref: /original-bsd/usr.bin/f77/libU77/perror_.c (revision 0b685140)
1 /*
2 char id_perror[] = "@(#)perror_.c	1.2";
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 	unit	*lu;
26 	char	buf[40];
27 	char	*mesg = s + len;
28 
29 	while (len > 0 && *--mesg == ' ')
30 		len--;
31 	if (errno >=0 && errno < sys_nerr)
32 		mesg = sys_errlist[errno];
33 	else if (errno >= F_ER && errno < (F_ER + f_nerr))
34 		mesg = f_errlist[errno - F_ER];
35 	else
36 	{
37 		sprintf(buf, "%d: unknown error number", errno);
38 		mesg = buf;
39 	}
40 	lu = &units[STDERR];
41 	if (!lu->uwrt)
42 		nowwriting(lu);
43 	while (len-- > 0)
44 		putc(*s++, lu->ufd);
45 	fprintf(lu->ufd, ": %s\n", mesg);
46 }
47