1*3a628b46Sschwarze /* $OpenBSD: strerror_l.c,v 1.1 2017/09/05 03:16:13 schwarze Exp $ */
2*3a628b46Sschwarze /*
3*3a628b46Sschwarze * Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org>
4*3a628b46Sschwarze *
5*3a628b46Sschwarze * Permission to use, copy, modify, and distribute this software for any
6*3a628b46Sschwarze * purpose with or without fee is hereby granted, provided that the above
7*3a628b46Sschwarze * copyright notice and this permission notice appear in all copies.
8*3a628b46Sschwarze *
9*3a628b46Sschwarze * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10*3a628b46Sschwarze * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11*3a628b46Sschwarze * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12*3a628b46Sschwarze * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13*3a628b46Sschwarze * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14*3a628b46Sschwarze * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15*3a628b46Sschwarze * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16*3a628b46Sschwarze */
17*3a628b46Sschwarze
18*3a628b46Sschwarze #include <limits.h>
19*3a628b46Sschwarze #include <string.h>
20*3a628b46Sschwarze
21*3a628b46Sschwarze #include "thread_private.h"
22*3a628b46Sschwarze
23*3a628b46Sschwarze char *
strerror_l(int errnum,locale_t locale)24*3a628b46Sschwarze strerror_l(int errnum, locale_t locale)
25*3a628b46Sschwarze {
26*3a628b46Sschwarze static char sel_buf[NL_TEXTMAX];
27*3a628b46Sschwarze _THREAD_PRIVATE_KEY(strerror_l);
28*3a628b46Sschwarze char *p = _THREAD_PRIVATE(strerror_l, sel_buf, NULL);
29*3a628b46Sschwarze
30*3a628b46Sschwarze return p == NULL ? "no buffer available in strerror_l" :
31*3a628b46Sschwarze strerror_r(errnum, p, sizeof(sel_buf)) ?
32*3a628b46Sschwarze "strerror_r failure" : p;
33*3a628b46Sschwarze }
34