12522Sdlw /* 223042Skre * Copyright (c) 1980 Regents of the University of California. 323042Skre * All rights reserved. The Berkeley software License Agreement 423042Skre * specifies the terms and conditions for redistribution. 52522Sdlw * 6*42409Sbostic * @(#)perror_.c 5.2 05/28/90 723042Skre */ 823042Skre 923042Skre /* 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 int sys_nerr; 232522Sdlw extern char *f_errlist[]; 242522Sdlw extern int f_nerr; 252522Sdlw extern unit units[]; 262522Sdlw 272522Sdlw perror_(s, len) 282522Sdlw char *s; long len; 292522Sdlw { 303892Sdlw unit *lu; 313892Sdlw char buf[40]; 323892Sdlw char *mesg = s + len; 33*42409Sbostic char *strerror(); 342522Sdlw 352522Sdlw while (len > 0 && *--mesg == ' ') 362522Sdlw len--; 372522Sdlw if (errno >=0 && errno < sys_nerr) 38*42409Sbostic mesg = strerror(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