xref: /csrg-svn/usr.bin/f77/libU77/perror_.c (revision 23042)
12522Sdlw /*
2*23042Skre  * Copyright (c) 1980 Regents of the University of California.
3*23042Skre  * All rights reserved.  The Berkeley software License Agreement
4*23042Skre  * specifies the terms and conditions for redistribution.
52522Sdlw  *
6*23042Skre  *	@(#)perror_.c	5.1	06/07/85
7*23042Skre  */
8*23042Skre 
9*23042Skre /*
102522Sdlw  * write a standard error message to the standard error output
112522Sdlw  *
122522Sdlw  * calling sequence:
132522Sdlw  *	call perror(string)
142522Sdlw  * where:
152522Sdlw  *	string will be written preceeding the standard error message
162522Sdlw  */
172522Sdlw 
182522Sdlw #include	<stdio.h>
192522Sdlw #include	"../libI77/fiodefs.h"
202522Sdlw #include	"../libI77/f_errno.h"
212522Sdlw 
222522Sdlw extern char *sys_errlist[];
232522Sdlw extern int sys_nerr;
242522Sdlw extern char *f_errlist[];
252522Sdlw extern int f_nerr;
262522Sdlw extern unit units[];
272522Sdlw 
282522Sdlw perror_(s, len)
292522Sdlw char *s; long len;
302522Sdlw {
313892Sdlw 	unit	*lu;
323892Sdlw 	char	buf[40];
333892Sdlw 	char	*mesg = s + len;
342522Sdlw 
352522Sdlw 	while (len > 0 && *--mesg == ' ')
362522Sdlw 		len--;
372522Sdlw 	if (errno >=0 && errno < sys_nerr)
382522Sdlw 		mesg = sys_errlist[errno];
392522Sdlw 	else if (errno >= F_ER && errno < (F_ER + f_nerr))
402522Sdlw 		mesg = f_errlist[errno - F_ER];
412522Sdlw 	else
422522Sdlw 	{
432522Sdlw 		sprintf(buf, "%d: unknown error number", errno);
442522Sdlw 		mesg = buf;
452522Sdlw 	}
463892Sdlw 	lu = &units[STDERR];
473892Sdlw 	if (!lu->uwrt)
483892Sdlw 		nowwriting(lu);
492522Sdlw 	while (len-- > 0)
503892Sdlw 		putc(*s++, lu->ufd);
513892Sdlw 	fprintf(lu->ufd, ": %s\n", mesg);
522522Sdlw }
53