xref: /original-bsd/lib/libc/string/strerror.3 (revision a6d8c59f)
1.\" Copyright (c) 1980, 1991 Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" This code is derived from software contributed to Berkeley by
5.\" the American National Standards Committee X3, on Information
6.\" Processing Systems.
7.\"
8.\" %sccs.include.redist.man%
9.\"
10.\"     @(#)strerror.3	6.10 (Berkeley) 10/04/92
11.\"
12.Dd
13.Dt STRERROR 3
14.Os BSD 4
15.Sh NAME
16.Nm perror ,
17.Nm strerror ,
18.Nm sys_errlist ,
19.Nm sys_nerr
20.Nd system error messages
21.Sh SYNOPSIS
22.Fd #include <errno.h>
23.Vt extern int errno;
24.Fd #include <stdio.h>
25.Vt extern int sys_nerr;
26.Vt extern char *sys_errlist[];
27.Fd #include <stdio.h>
28.Ft void
29.Fn perror "const char *string"
30.Fd #include <errno.h>
31.Fd #include <string.h>
32.Ft char *
33.Fn strerror "int errnum"
34.Sh DESCRIPTION
35The
36.Fn strerror
37and
38.Fn perror
39functions lookup the error message string affiliated with an
40error number.
41.Pp
42The
43.Fn sterror
44function accepts an error number argument
45.Fa errnum
46and
47returns a pointer to the corresponding
48message string.
49.Pp
50The
51.Fn perror
52function finds the error message corresponding to the current
53value of the global variable
54.Va errno
55and writes it, followed by a new-line, to the
56.Em stderr .
57If the argument
58.Fa string
59is
60.Pf non- Dv NULL
61it is pre-appended to the message
62string and separated from it by
63a colon and space
64.Pq Ql \&:\ \& .
65If
66.Fa string
67is
68.Dv NULL
69only the error message string is printed.
70.Pp
71The message strings can be accessed directly using the external
72character array
73.Fa sys_errlist .
74The external value
75.Fa sys_nerr
76contains a count of the messages in
77.Fa sys_errlist .
78The use of these variables is deprecated;
79.Fn strerror
80should be used instead.
81.Sh SEE ALSO
82.Xr intro 2 ,
83.Xr psignal 3
84.Sh HISTORY
85The
86.Fn strerror
87and
88.Fn perror
89functions are
90.Ud .
91