xref: /csrg-svn/lib/libc/string/strerror.3 (revision 62927)
1*62927Sbostic.\" Copyright (c) 1980, 1991, 1993
2*62927Sbostic.\"	The Regents of the University of California.  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*62927Sbostic.\"     @(#)strerror.3	8.1 (Berkeley) 06/09/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"
2558376Sbostic.Vt extern char *sys_errlist[];
2658376Sbostic.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
3558376Sbosticfunctions look up the error message string corresponding to an
3648351Scaelerror number.
3748351Scael.Pp
3848351ScaelThe
3958376Sbostic.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
5158376Sbostic.Pq Xr intro 2
5258376Sbosticand writes it, followed by a newline, to the
5358376Sbosticstandard error file descriptor.
5448351ScaelIf the argument
5548351Scael.Fa string
5648351Scaelis
5758376Sbostic.Pf non- Dv NULL ,
5858376Sbosticit is prepended to the message
5948351Scaelstring and separated from it by
6048351Scaela colon and space
6148351Scael.Pq Ql \&:\ \& .
6248351ScaelIf
6348351Scael.Fa string
6448351Scaelis
6558376Sbostic.Dv NULL ,
6648351Scaelonly the error message string is printed.
6748351Scael.Pp
6858376SbosticIf
6958376Sbostic.Fa errnum
7058376Sbosticis not a recognized error number,
7158376Sbosticthe error message string will contain
7258376Sbostic.Dq Li "Unknown error:\0
7358376Sbosticfollowed by the error number in decimal.
7458376Sbostic.Pp
7536225SbosticThe message strings can be accessed directly using the external
7658376Sbosticarray
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
9362926Sbosticfunctions first appeared in 4.4BSD.
9458376Sbostic.Sh BUGS
9558376SbosticFor unknown error numbers, the
9658376Sbostic.Fn strerror
9758376Sbosticfunction will return its result in a static buffer which
9858376Sbosticmay be overwritten by subsequent calls.
99