Commit | Line | Data |
---|---|---|
bb0cfa24 DF |
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 | ||
2ce81398 | 7 | #if defined(LIBC_SCCS) && !defined(lint) |
24bc97a1 | 8 | static char sccsid[] = "@(#)perror.c 5.3 (Berkeley) %G%"; |
2ce81398 | 9 | #endif LIBC_SCCS and not lint |
bb0cfa24 | 10 | |
716337de BJ |
11 | /* |
12 | * Print the error indicated | |
13 | * in the cerror cell. | |
14 | */ | |
df5b5637 SL |
15 | #include <sys/types.h> |
16 | #include <sys/uio.h> | |
716337de BJ |
17 | |
18 | int errno; | |
24bc97a1 KB |
19 | extern int sys_nerr; |
20 | extern char *sys_errlist[]; | |
716337de | 21 | perror(s) |
df5b5637 | 22 | char *s; |
716337de | 23 | { |
df5b5637 SL |
24 | struct iovec iov[4]; |
25 | register struct iovec *v = iov; | |
716337de | 26 | |
df5b5637 SL |
27 | if (s && *s) { |
28 | v->iov_base = s; | |
29 | v->iov_len = strlen(s); | |
30 | v++; | |
31 | v->iov_base = ": "; | |
32 | v->iov_len = 2; | |
33 | v++; | |
716337de | 34 | } |
df5b5637 SL |
35 | v->iov_base = errno < sys_nerr ? sys_errlist[errno] : "Unknown error"; |
36 | v->iov_len = strlen(v->iov_base); | |
37 | v++; | |
38 | v->iov_base = "\n"; | |
39 | v->iov_len = 1; | |
40 | writev(2, iov, (v - iov) + 1); | |
716337de | 41 | } |