xref: /original-bsd/usr.bin/f77/libU77/perror_.c (revision 540a81df)
1 /*
2  * Copyright (c) 1980 Regents of the University of California.
3  * All rights reserved.  The Berkeley software License Agreement
4  * specifies the terms and conditions for redistribution.
5  *
6  *	@(#)perror_.c	5.2	05/28/90
7  */
8 
9 /*
10  * write a standard error message to the standard error output
11  *
12  * calling sequence:
13  *	call perror(string)
14  * where:
15  *	string will be written preceeding the standard error message
16  */
17 
18 #include	<stdio.h>
19 #include	"../libI77/fiodefs.h"
20 #include	"../libI77/f_errno.h"
21 
22 extern int sys_nerr;
23 extern char *f_errlist[];
24 extern int f_nerr;
25 extern unit units[];
26 
27 perror_(s, len)
28 char *s; long len;
29 {
30 	unit	*lu;
31 	char	buf[40];
32 	char	*mesg = s + len;
33 	char	*strerror();
34 
35 	while (len > 0 && *--mesg == ' ')
36 		len--;
37 	if (errno >=0 && errno < sys_nerr)
38 		mesg = strerror(errno);
39 	else if (errno >= F_ER && errno < (F_ER + f_nerr))
40 		mesg = f_errlist[errno - F_ER];
41 	else
42 	{
43 		sprintf(buf, "%d: unknown error number", errno);
44 		mesg = buf;
45 	}
46 	lu = &units[STDERR];
47 	if (!lu->uwrt)
48 		nowwriting(lu);
49 	while (len-- > 0)
50 		putc(*s++, lu->ufd);
51 	fprintf(lu->ufd, ": %s\n", mesg);
52 }
53