xref: /original-bsd/lib/libc/string/strerror.3 (revision 3705696b)
1.\" Copyright (c) 1980, 1991, 1993
2.\"	The Regents of the University of California.  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	8.1 (Berkeley) 06/09/93
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 <stdio.h>
23.Ft void
24.Fn perror "const char *string"
25.Vt extern char *sys_errlist[];
26.Vt extern int sys_nerr;
27.Fd #include <string.h>
28.Ft char *
29.Fn strerror "int errnum"
30.Sh DESCRIPTION
31The
32.Fn strerror
33and
34.Fn perror
35functions look up the error message string corresponding to an
36error number.
37.Pp
38The
39.Fn strerror
40function accepts an error number argument
41.Fa errnum
42and
43returns a pointer to the corresponding
44message string.
45.Pp
46The
47.Fn perror
48function finds the error message corresponding to the current
49value of the global variable
50.Va errno
51.Pq Xr intro 2
52and writes it, followed by a newline, to the
53standard error file descriptor.
54If the argument
55.Fa string
56is
57.Pf non- Dv NULL ,
58it is prepended to the message
59string and separated from it by
60a colon and space
61.Pq Ql \&:\ \& .
62If
63.Fa string
64is
65.Dv NULL ,
66only the error message string is printed.
67.Pp
68If
69.Fa errnum
70is not a recognized error number,
71the error message string will contain
72.Dq Li "Unknown error:\0
73followed by the error number in decimal.
74.Pp
75The message strings can be accessed directly using the external
76array
77.Fa sys_errlist .
78The external value
79.Fa sys_nerr
80contains a count of the messages in
81.Fa sys_errlist .
82The use of these variables is deprecated;
83.Fn strerror
84should be used instead.
85.Sh SEE ALSO
86.Xr intro 2 ,
87.Xr psignal 3
88.Sh HISTORY
89The
90.Fn strerror
91and
92.Fn perror
93functions first appeared in 4.4BSD.
94.Sh BUGS
95For unknown error numbers, the
96.Fn strerror
97function will return its result in a static buffer which
98may be overwritten by subsequent calls.
99