1.\" $OpenBSD: strerror.3,v 1.16 2019/05/16 13:35:16 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: May 16 2019 $ 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 ERRORS 99All these functions may fail if: 100.Bl -tag -width Er 101.It Bq Er EINVAL 102.Fa errnum 103is not a valid error number. 104The returned error string will consist of an error message that includes 105.Fa errnum . 106.El 107.Pp 108.Fn strerror_r 109may also fail if: 110.Bl -tag -width Er 111.It Bq Er ERANGE 112The error message is larger than 113.Fa buflen 114characters. 115The message will be truncated to fit. 116.El 117.Sh SEE ALSO 118.Xr intro 2 , 119.Xr newlocale 3 , 120.Xr perror 3 , 121.Xr setlocale 3 122.Sh STANDARDS 123The 124.Fn strerror 125function conforms to 126.St -isoC-99 . 127The 128.Fn strerror_l 129and 130.Fn strerror_r 131functions conform to 132.St -p1003.1-2008 . 133.Sh HISTORY 134The 135.Fn strerror 136function has been available since 137.Bx 4.3 Reno , 138.Fn strerror_r 139since 140.Ox 3.3 , 141and 142.Fn strerror_l 143since 144.Ox 6.2 . 145.Sh CAVEATS 146On systems other than 147.Ox , 148the 149.Dv LC_MESSAGES 150.Xr locale 1 151category can cause different strings to be returned instead of the 152normal error messages; see CAVEATS in 153.Xr setlocale 3 154for details. 155