]>
code.delx.au - pulseaudio/blob - src/pulsecore/core-error.c
2 This file is part of PulseAudio.
4 Copyright 2004-2006 Lennart Poettering
5 Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
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 of the License,
10 or (at your option) any later version.
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.
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
32 #include <pulse/utf8.h>
33 #include <pulse/xmalloc.h>
35 #include <pulsecore/core-util.h>
36 #include <pulsecore/native-common.h>
37 #include <pulsecore/thread.h>
38 #include <pulsecore/macro.h>
39 #include <pulsecore/log.h>
41 #include "core-error.h"
43 PA_STATIC_TLS_DECLARE(cstrerror
, pa_xfree
);
45 const char* pa_cstrerror(int errnum
) {
46 const char *original
= NULL
;
50 if ((t
= PA_STATIC_TLS_GET(cstrerror
)))
53 #if defined(HAVE_STRERROR_R) && defined(__GLIBC__)
54 original
= strerror_r(errnum
, errbuf
, sizeof(errbuf
));
55 #elif defined(HAVE_STRERROR_R)
56 if (strerror_r(errnum
, errbuf
, sizeof(errbuf
)) == 0) {
57 errbuf
[sizeof(errbuf
) - 1] = 0;
61 /* This might not be thread safe, but we hope for the best */
62 original
= strerror(errnum
);
66 pa_snprintf(errbuf
, sizeof(errbuf
), "Unknown error %i", errnum
);
70 if (!(translated
= pa_locale_to_utf8(original
))) {
71 pa_log_warn("Unable to convert error string to locale, filtering.");
72 translated
= pa_utf8_filter(original
);
75 PA_STATIC_TLS_SET(cstrerror
, translated
);