xref: /minix3/lib/libc/string/strerror.3 (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc.\" $NetBSD: strerror.3,v 1.18 2015/05/09 19:01:53 dholland Exp $
22fe8fb19SBen Gras.\"
32fe8fb19SBen Gras.\" Copyright (c) 1980, 1991, 1993
42fe8fb19SBen Gras.\"	The Regents of the University of California.  All rights reserved.
52fe8fb19SBen Gras.\"
62fe8fb19SBen Gras.\" This code is derived from software contributed to Berkeley by
72fe8fb19SBen Gras.\" the American National Standards Committee X3, on Information
82fe8fb19SBen Gras.\" Processing Systems.
92fe8fb19SBen Gras.\"
102fe8fb19SBen Gras.\" Redistribution and use in source and binary forms, with or without
112fe8fb19SBen Gras.\" modification, are permitted provided that the following conditions
122fe8fb19SBen Gras.\" are met:
132fe8fb19SBen Gras.\" 1. Redistributions of source code must retain the above copyright
142fe8fb19SBen Gras.\"    notice, this list of conditions and the following disclaimer.
152fe8fb19SBen Gras.\" 2. Redistributions in binary form must reproduce the above copyright
162fe8fb19SBen Gras.\"    notice, this list of conditions and the following disclaimer in the
172fe8fb19SBen Gras.\"    documentation and/or other materials provided with the distribution.
182fe8fb19SBen Gras.\" 3. Neither the name of the University nor the names of its contributors
192fe8fb19SBen Gras.\"    may be used to endorse or promote products derived from this software
202fe8fb19SBen Gras.\"    without specific prior written permission.
212fe8fb19SBen Gras.\"
222fe8fb19SBen Gras.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
232fe8fb19SBen Gras.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
242fe8fb19SBen Gras.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
252fe8fb19SBen Gras.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
262fe8fb19SBen Gras.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
272fe8fb19SBen Gras.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
282fe8fb19SBen Gras.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
292fe8fb19SBen Gras.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
302fe8fb19SBen Gras.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
312fe8fb19SBen Gras.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
322fe8fb19SBen Gras.\" SUCH DAMAGE.
332fe8fb19SBen Gras.\"
342fe8fb19SBen Gras.\"     @(#)strerror.3	8.1 (Berkeley) 6/9/93
35*0a6a1f1dSLionel Sambuc.Dd May 9, 2015
362fe8fb19SBen Gras.Dt STRERROR 3
372fe8fb19SBen Gras.Os
382fe8fb19SBen Gras.Sh NAME
392fe8fb19SBen Gras.Nm perror ,
402fe8fb19SBen Gras.Nm strerror ,
412fe8fb19SBen Gras.Nm strerror_r ,
422fe8fb19SBen Gras.Nm sys_errlist ,
432fe8fb19SBen Gras.Nm sys_nerr
442fe8fb19SBen Gras.Nd system error messages
452fe8fb19SBen Gras.Sh LIBRARY
462fe8fb19SBen Gras.Lb libc
472fe8fb19SBen Gras.Sh SYNOPSIS
482fe8fb19SBen Gras.In stdio.h
492fe8fb19SBen Gras.Ft void
502fe8fb19SBen Gras.Fn perror "const char *string"
512fe8fb19SBen Gras.In errno.h
522fe8fb19SBen Gras.Vt extern const char * const sys_errlist[] ;
532fe8fb19SBen Gras.Vt extern const int sys_nerr ;
542fe8fb19SBen Gras.In string.h
552fe8fb19SBen Gras.Ft "char *"
562fe8fb19SBen Gras.Fn strerror "int errnum"
572fe8fb19SBen Gras.Ft int
582fe8fb19SBen Gras.Fn strerror_r "int errnum" "char *strerrbuf" "size_t buflen"
592fe8fb19SBen Gras.Sh DESCRIPTION
602fe8fb19SBen GrasThe
612fe8fb19SBen Gras.Fn strerror ,
622fe8fb19SBen Gras.Fn strerror_r ,
632fe8fb19SBen Grasand
642fe8fb19SBen Gras.Fn perror
652fe8fb19SBen Grasfunctions look up the language-dependent error message
662fe8fb19SBen Grasstring corresponding to an error number.
672fe8fb19SBen Gras.Pp
682fe8fb19SBen GrasThe
692fe8fb19SBen Gras.Fn strerror
702fe8fb19SBen Grasfunction accepts an error number argument
712fe8fb19SBen Gras.Fa errnum
722fe8fb19SBen Grasand returns a pointer to the corresponding
732fe8fb19SBen Grasmessage string.
742fe8fb19SBen Gras.Pp
752fe8fb19SBen GrasThe
762fe8fb19SBen Gras.Fn strerror_r
772fe8fb19SBen Grasfunction renders the same result into
782fe8fb19SBen Gras.Fa strerrbuf
792fe8fb19SBen Grasfor a maximum of
802fe8fb19SBen Gras.Fa buflen
812fe8fb19SBen Grascharacters and returns 0 upon success.
822fe8fb19SBen Gras.Pp
832fe8fb19SBen GrasThe
842fe8fb19SBen Gras.Fn perror
852fe8fb19SBen Grasfunction finds the error message corresponding to the current
862fe8fb19SBen Grasvalue of the global variable
872fe8fb19SBen Gras.Va errno
882fe8fb19SBen Gras.Pq Xr intro 2
892fe8fb19SBen Grasand writes it, followed by a newline, to the
902fe8fb19SBen Grasstandard error file descriptor.
912fe8fb19SBen GrasIf the argument
922fe8fb19SBen Gras.Fa string
932fe8fb19SBen Grasis
942fe8fb19SBen Gras.Pf non- Dv NULL
952fe8fb19SBen Grasand does not point to the nul character,
962fe8fb19SBen Grasthis string is prepended to the message
972fe8fb19SBen Grasstring and separated from it by
982fe8fb19SBen Grasa colon and space
992fe8fb19SBen Gras.Pq Dq Li ":\ " ;
1002fe8fb19SBen Grasotherwise, only the error message string is printed.
1012fe8fb19SBen GrasNote that in most cases the
1022fe8fb19SBen Gras.Xr err 3
1032fe8fb19SBen Grasand
1042fe8fb19SBen Gras.Xr warn 3
1052fe8fb19SBen Grasfamily of functions is preferable to
1062fe8fb19SBen Gras.Fn perror ;
1072fe8fb19SBen Grasthey are more flexible and also print the program name.
1082fe8fb19SBen Gras.Pp
1092fe8fb19SBen GrasIf the error number is not recognized, these functions pass an error message
1102fe8fb19SBen Grasstring containing
1112fe8fb19SBen Gras.Dq Li "Unknown error:\ "
1122fe8fb19SBen Grasfollowed by the error number in decimal.
1132fe8fb19SBen GrasTo warn about this,
1142fe8fb19SBen Gras.Fn strerror
1152fe8fb19SBen Grassets
1162fe8fb19SBen Gras.Dv errno
1172fe8fb19SBen Grasto
1182fe8fb19SBen Gras.Er EINVAL ,
1192fe8fb19SBen Grasand
1202fe8fb19SBen Gras.Fn strerror_r
1212fe8fb19SBen Grasreturns
1222fe8fb19SBen Gras.Er EINVAL .
1232fe8fb19SBen GrasError numbers recognized by this implementation fall in
1242fe8fb19SBen Grasthe range 0 \*[Lt]
1252fe8fb19SBen Gras.Fa errnum
1262fe8fb19SBen Gras\*[Lt]
1272fe8fb19SBen Gras.Fa sys_nerr .
1282fe8fb19SBen Gras.Pp
1292fe8fb19SBen GrasIf insufficient storage is provided in
1302fe8fb19SBen Gras.Fa strerrbuf
1312fe8fb19SBen Gras(as specified in
1322fe8fb19SBen Gras.Fa buflen )
1332fe8fb19SBen Grasto contain the error string,
1342fe8fb19SBen Gras.Fn strerror_r
1352fe8fb19SBen Grasreturns
1362fe8fb19SBen Gras.Er ERANGE
1372fe8fb19SBen Grasand
1382fe8fb19SBen Gras.Fa strerrbuf
1392fe8fb19SBen Graswill contain an error message that has been truncated and
1402fe8fb19SBen Gras.Dv NUL
1412fe8fb19SBen Grasterminated to fit the length specified by
1422fe8fb19SBen Gras.Fa buflen .
1432fe8fb19SBen Gras.Pp
1442fe8fb19SBen GrasThe message strings can be accessed directly using the external
1452fe8fb19SBen Grasarray
1462fe8fb19SBen Gras.Va sys_errlist .
1472fe8fb19SBen GrasThe external value
1482fe8fb19SBen Gras.Va sys_nerr
1492fe8fb19SBen Grascontains a count of the messages in
1502fe8fb19SBen Gras.Va sys_errlist .
1512fe8fb19SBen GrasThe use of these variables is deprecated;
1522fe8fb19SBen Gras.Fn strerror
1532fe8fb19SBen Grasor
1542fe8fb19SBen Gras.Fn strerror_r
1552fe8fb19SBen Grasshould be used instead.
1562fe8fb19SBen Gras.Sh SEE ALSO
1572fe8fb19SBen Gras.Xr intro 2 ,
1582fe8fb19SBen Gras.Xr err 3 ,
1592fe8fb19SBen Gras.Xr psignal 3 ,
1602fe8fb19SBen Gras.Xr warn 3
1612fe8fb19SBen Gras.Sh STANDARDS
1622fe8fb19SBen GrasThe
1632fe8fb19SBen Gras.Fn perror
1642fe8fb19SBen Grasand
1652fe8fb19SBen Gras.Fn strerror
1662fe8fb19SBen Grasfunctions conform to
1672fe8fb19SBen Gras.St -isoC-99 .
1682fe8fb19SBen GrasThe
1692fe8fb19SBen Gras.Fn strerror_r
1702fe8fb19SBen Grasfunction conforms to
1712fe8fb19SBen Gras.St -p1003.1-2001 .
1722fe8fb19SBen Gras.Sh HISTORY
1732fe8fb19SBen GrasThe
1742fe8fb19SBen Gras.Fn perror
175*0a6a1f1dSLionel Sambucfunction first appeared in
176*0a6a1f1dSLionel Sambuc.At v4 .
177*0a6a1f1dSLionel SambucThe
178*0a6a1f1dSLionel Sambuc.Fn strerror
179*0a6a1f1dSLionel Sambucfunction first appeared in
180*0a6a1f1dSLionel Sambuc.Bx 4.3 Reno .
1812fe8fb19SBen GrasThe
1822fe8fb19SBen Gras.Fn strerror_r
1832fe8fb19SBen Grasfunction first appeared in
1842fe8fb19SBen Gras.Nx 4.0 .
1852fe8fb19SBen Gras.Sh BUGS
1862fe8fb19SBen GrasFor unknown error numbers, the
1872fe8fb19SBen Gras.Fn strerror
1882fe8fb19SBen Grasfunction will return its result in a static buffer which
1892fe8fb19SBen Grasmay be overwritten by subsequent calls.
1902fe8fb19SBen Gras.Pp
1912fe8fb19SBen GrasThe return type for
1922fe8fb19SBen Gras.Fn strerror
1932fe8fb19SBen Grasis missing a type-qualifier; it should actually be
1942fe8fb19SBen Gras.Vt const char * .
1952fe8fb19SBen Gras.Pp
1962fe8fb19SBen GrasPrograms that use the deprecated
1972fe8fb19SBen Gras.Va sys_errlist
1982fe8fb19SBen Grasvariable often fail to compile because they declare it
1992fe8fb19SBen Grasinconsistently.
200