Branch data Line data Source code
1 : : /***
2 : : This file is part of PulseAudio.
3 : :
4 : : Copyright 2004-2006 Lennart Poettering
5 : : Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
6 : :
7 : : PulseAudio is free software; you can redistribute it and/or modify
8 : : it under the terms of the GNU Lesser General Public License as published
9 : : by the Free Software Foundation; either version 2.1 of the License,
10 : : or (at your option) any later version.
11 : :
12 : : PulseAudio is distributed in the hope that it will be useful, but
13 : : WITHOUT ANY WARRANTY; without even the implied warranty of
14 : : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 : : General Public License for more details.
16 : :
17 : : You should have received a copy of the GNU Lesser General Public License
18 : : along with PulseAudio; if not, write to the Free Software
19 : : Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 : : USA.
21 : : ***/
22 : :
23 : : #ifdef HAVE_CONFIG_H
24 : : #include <config.h>
25 : : #endif
26 : :
27 : : #include <errno.h>
28 : : #include <stdio.h>
29 : : #include <stdlib.h>
30 : : #include <string.h>
31 : :
32 : : #include <pulse/utf8.h>
33 : : #include <pulse/xmalloc.h>
34 : :
35 : : #include <pulsecore/thread.h>
36 : : #include <pulsecore/macro.h>
37 : : #include <pulsecore/log.h>
38 : :
39 : : #include "core-error.h"
40 : :
41 [ - + ][ # # ]: 27 : PA_STATIC_TLS_DECLARE(cstrerror, pa_xfree);
[ # # ][ # # ]
42 : :
43 : 0 : const char* pa_cstrerror(int errnum) {
44 : 0 : const char *original = NULL;
45 : : char *translated, *t;
46 : : char errbuf[128];
47 : :
48 [ # # ]: 0 : if (errnum < 0)
49 : 0 : errnum = -errnum;
50 : :
51 [ # # ]: 0 : if ((t = PA_STATIC_TLS_GET(cstrerror)))
52 : 0 : pa_xfree(t);
53 : :
54 : : #if defined(HAVE_STRERROR_R) && defined(__GLIBC__)
55 : 0 : original = strerror_r(errnum, errbuf, sizeof(errbuf));
56 : : #elif defined(HAVE_STRERROR_R)
57 : : if (strerror_r(errnum, errbuf, sizeof(errbuf)) == 0) {
58 : : errbuf[sizeof(errbuf) - 1] = 0;
59 : : original = errbuf;
60 : : }
61 : : #else
62 : : /* This might not be thread safe, but we hope for the best */
63 : : original = strerror(errnum);
64 : : #endif
65 : :
66 [ # # ]: 0 : if (!original) {
67 : 0 : pa_snprintf(errbuf, sizeof(errbuf), "Unknown error %i", errnum);
68 : 0 : original = errbuf;
69 : : }
70 : :
71 [ # # ]: 0 : if (!(translated = pa_locale_to_utf8(original))) {
72 : 0 : pa_log_warn("Unable to convert error string to locale, filtering.");
73 : 0 : translated = pa_utf8_filter(original);
74 : : }
75 : :
76 : : PA_STATIC_TLS_SET(cstrerror, translated);
77 : :
78 : 0 : return translated;
79 : : }
|