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