xref: /csrg-svn/lib/libc/string/strerror.3 (revision 58376)
148351Scael.\" Copyright (c) 1980, 1991 Regents of the University of California.
248351Scael.\" All rights reserved.
320436Smckusick.\"
450314Sbostic.\" This code is derived from software contributed to Berkeley by
550314Sbostic.\" the American National Standards Committee X3, on Information
650314Sbostic.\" Processing Systems.
750314Sbostic.\"
848351Scael.\" %sccs.include.redist.man%
920436Smckusick.\"
10*58376Sbostic.\"     @(#)strerror.3	6.11 (Berkeley) 03/02/93
1148351Scael.\"
1248351Scael.Dd
1348351Scael.Dt STRERROR 3
1448351Scael.Os BSD 4
1548351Scael.Sh NAME
1648351Scael.Nm perror ,
1748351Scael.Nm strerror ,
1848351Scael.Nm sys_errlist ,
1948351Scael.Nm sys_nerr
2048351Scael.Nd system error messages
2148351Scael.Sh SYNOPSIS
2256414Sbostic.Fd #include <stdio.h>
2348351Scael.Ft void
2448351Scael.Fn perror "const char *string"
25*58376Sbostic.Vt extern char *sys_errlist[];
26*58376Sbostic.Vt extern int sys_nerr;
2756414Sbostic.Fd #include <string.h>
2848351Scael.Ft char *
2948351Scael.Fn strerror "int errnum"
3048351Scael.Sh DESCRIPTION
3148351ScaelThe
3248351Scael.Fn strerror
3348351Scaeland
3448351Scael.Fn perror
35*58376Sbosticfunctions look up the error message string corresponding to an
3648351Scaelerror number.
3748351Scael.Pp
3848351ScaelThe
39*58376Sbostic.Fn strerror
4048351Scaelfunction accepts an error number argument
4148351Scael.Fa errnum
4248351Scaeland
4348351Scaelreturns a pointer to the corresponding
4448351Scaelmessage string.
4548351Scael.Pp
4648351ScaelThe
4748351Scael.Fn perror
4848351Scaelfunction finds the error message corresponding to the current
4948351Scaelvalue of the global variable
5048351Scael.Va errno
51*58376Sbostic.Pq Xr intro 2
52*58376Sbosticand writes it, followed by a newline, to the
53*58376Sbosticstandard error file descriptor.
5448351ScaelIf the argument
5548351Scael.Fa string
5648351Scaelis
57*58376Sbostic.Pf non- Dv NULL ,
58*58376Sbosticit is prepended to the message
5948351Scaelstring and separated from it by
6048351Scaela colon and space
6148351Scael.Pq Ql \&:\ \& .
6248351ScaelIf
6348351Scael.Fa string
6448351Scaelis
65*58376Sbostic.Dv NULL ,
6648351Scaelonly the error message string is printed.
6748351Scael.Pp
68*58376SbosticIf
69*58376Sbostic.Fa errnum
70*58376Sbosticis not a recognized error number,
71*58376Sbosticthe error message string will contain
72*58376Sbostic.Dq Li "Unknown error:\0
73*58376Sbosticfollowed by the error number in decimal.
74*58376Sbostic.Pp
7536225SbosticThe message strings can be accessed directly using the external
76*58376Sbosticarray
7748351Scael.Fa sys_errlist .
7848351ScaelThe external value
7948351Scael.Fa sys_nerr
8048351Scaelcontains a count of the messages in
8148351Scael.Fa sys_errlist .
8247016SbosticThe use of these variables is deprecated;
8348351Scael.Fn strerror
8436225Sbosticshould be used instead.
8548351Scael.Sh SEE ALSO
8648351Scael.Xr intro 2 ,
8748351Scael.Xr psignal 3
8848351Scael.Sh HISTORY
8948351ScaelThe
9048351Scael.Fn strerror
9148351Scaeland
9248351Scael.Fn perror
9348351Scaelfunctions are
9448351Scael.Ud .
95*58376Sbostic.Sh BUGS
96*58376SbosticFor unknown error numbers, the
97*58376Sbostic.Fn strerror
98*58376Sbosticfunction will return its result in a static buffer which
99*58376Sbosticmay be overwritten by subsequent calls.
100