]> git.sesse.net Git - vlc/blob - src/posix/error.c
cosmetics: contrib: libxml2: split configuration across multiple lines
[vlc] / src / posix / error.c
1 /*****************************************************************************
2  * error.c: POSIX error messages formatting
3  *****************************************************************************
4  * Copyright © 2013 Rémi Denis-Courmont
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation; either version 2.1 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19  *****************************************************************************/
20
21 #ifdef HAVE_CONFIG_H
22 # include "config.h"
23 #endif
24
25 #include <string.h>
26 #include <locale.h>
27
28 #include <vlc_common.h>
29
30 static const char *vlc_strerror_l(int errnum, const char *lname)
31 {
32     locale_t loc = newlocale(LC_MESSAGES_MASK, lname, (locale_t)0);
33     const char *buf = strerror_l(errnum, loc);
34
35     freelocale(loc);
36     return buf;
37 }
38
39 /**
40  * Formats an error message in the current locale.
41  * @param errnum error number (as in errno.h)
42  * @return A string pointer, valid until the next call to a function of the
43  * strerror() family in the same thread. This function cannot fail.
44  */
45 const char *vlc_strerror(int errnum)
46 {
47     /* We cannot simply use strerror() here, since it is not thread-safe. */
48     return vlc_strerror_l(errnum, "");
49 }
50
51 /**
52  * Formats an error message in the POSIX/C locale (i.e. American English).
53  * @param errnum error number (as in errno.h)
54  * @return A string pointer, valid until the next call to a function of the
55  * strerror() family in the same thread. This function cannot fail.
56  */
57 const char *vlc_strerror_c(int errnum)
58 {
59     return vlc_strerror_l(errnum, "C");
60 }