xref: /original-bsd/lib/libc/string/strerror.3 (revision 84fd512e)
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.9 (Berkeley) 06/29/91
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.Vt extern int errno;
23.Vt extern char *sys_errlist[];
24.Fd #include <stdio.h>
25.Ft void
26.Fn perror "const char *string"
27.Ft char *
28.Fn strerror "int errnum"
29.Sh DESCRIPTION
30The
31.Fn strerror
32and
33.Fn perror
34functions lookup the error message string affiliated with an
35error number.
36.Pp
37The
38.Fn sterror
39function accepts an error number argument
40.Fa errnum
41and
42returns a pointer to the corresponding
43message string.
44.Pp
45The
46.Fn perror
47function finds the error message corresponding to the current
48value of the global variable
49.Va errno
50and writes it, followed by a new-line, to the
51.Em stderr .
52If the argument
53.Fa string
54is
55.Pf non- Dv NULL
56it is pre-appended to the message
57string and separated from it by
58a colon and space
59.Pq Ql \&:\ \& .
60If
61.Fa string
62is
63.Dv NULL
64only the error message string is printed.
65.Pp
66The message strings can be accessed directly using the external
67character array
68.Fa sys_errlist .
69The external value
70.Fa sys_nerr
71contains a count of the messages in
72.Fa sys_errlist .
73The use of these variables is deprecated;
74.Fn strerror
75should be used instead.
76.Sh SEE ALSO
77.Xr intro 2 ,
78.Xr psignal 3
79.Sh HISTORY
80The
81.Fn strerror
82and
83.Fn perror
84functions are
85.Ud .
86