1.\" $OpenBSD: strerror.3,v 1.15 2017/09/05 03:16:13 schwarze Exp $ 2.\" 3.\" Copyright (c) 1980, 1991 Regents of the University of California. 4.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> 5.\" All rights reserved. 6.\" 7.\" This code is derived from software contributed to Berkeley by 8.\" the American National Standards Committee X3, on Information 9.\" Processing Systems. 10.\" 11.\" Redistribution and use in source and binary forms, with or without 12.\" modification, are permitted provided that the following conditions 13.\" are met: 14.\" 1. Redistributions of source code must retain the above copyright 15.\" notice, this list of conditions and the following disclaimer. 16.\" 2. Redistributions in binary form must reproduce the above copyright 17.\" notice, this list of conditions and the following disclaimer in the 18.\" documentation and/or other materials provided with the distribution. 19.\" 3. Neither the name of the University nor the names of its contributors 20.\" may be used to endorse or promote products derived from this software 21.\" without specific prior written permission. 22.\" 23.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33.\" SUCH DAMAGE. 34.\" 35.Dd $Mdocdate: September 5 2017 $ 36.Dt STRERROR 3 37.Os 38.Sh NAME 39.Nm strerror , 40.Nm strerror_l , 41.Nm strerror_r 42.Nd get error message string 43.Sh SYNOPSIS 44.In string.h 45.Ft char * 46.Fn strerror "int errnum" 47.Ft char * 48.Fn strerror_l "int errnum" "locale_t locale" 49.Ft int 50.Fn strerror_r "int errnum" "char *strerrbuf" "size_t buflen" 51.Sh DESCRIPTION 52These functions map the error number 53.Fa errnum 54to an error message string. 55.Pp 56.Fn strerror 57and 58.Fn strerror_l 59return a string containing a maximum of 60.Dv NL_TEXTMAX 61characters, including the trailing NUL. 62This string is not to be modified by the calling program. 63The string returned by 64.Fn strerror 65may be overwritten by subsequent calls to 66.Fn strerror 67in any thread. 68The string returned by 69.Fn strerror_l 70may be overwritten by subsequent calls to 71.Fn strerror_l 72in the same thread. 73.Pp 74.Fn strerror_r 75is a thread safe version of 76.Fn strerror 77that places the error message in the specified buffer 78.Fa strerrbuf . 79.Pp 80On 81.Ox , 82the global locale, the thread-specific locale, and the 83.Fa locale 84argument are ignored. 85.Sh RETURN VALUES 86.Fn strerror 87and 88.Fn strerror_l 89return a pointer to the error message string. 90If an error occurs, the error code is stored in 91.Va errno . 92.Pp 93.Fn strerror_r 94returns zero upon successful completion. 95If an error occurs, the error code is stored in 96.Va errno 97and the error code is returned. 98.Sh ENVIRONMENT 99On other operating systems, the behaviour of 100.Fn strerror 101and 102.Fn strerror_r 103may depend on the 104.Dv LC_MESSAGES 105.Xr locale 1 . 106.Sh ERRORS 107All these functions may fail if: 108.Bl -tag -width Er 109.It Bq Er EINVAL 110.Fa errnum 111is not a valid error number. 112The returned error string will consist of an error message that includes 113.Fa errnum . 114.El 115.Pp 116.Fn strerror_r 117may also fail if: 118.Bl -tag -width Er 119.It Bq Er ERANGE 120The error message is larger than 121.Fa buflen 122characters. 123The message will be truncated to fit. 124.El 125.Sh SEE ALSO 126.Xr intro 2 , 127.Xr newlocale 3 , 128.Xr perror 3 , 129.Xr setlocale 3 130.Sh STANDARDS 131The 132.Fn strerror 133function conforms to 134.St -isoC-99 . 135The 136.Fn strerror_l 137and 138.Fn strerror_r 139functions conform to 140.St -p1003.1-2008 . 141.Sh HISTORY 142The 143.Fn strerror 144function has been available since 145.Bx 4.3 Reno , 146.Fn strerror_r 147since 148.Ox 3.3 , 149and 150.Fn strerror_l 151since 152.Ox 6.2 . 153