Use libcharset instead of nl_langinfo(CODESET) if possible.
[ghc-base.git] / cbits / PrelIOUtils.c
1 /* 
2  * (c) The University of Glasgow 2002
3  *
4  * static versions of the inline functions in HsCore.h
5  */
6
7 #define INLINE
8
9 #ifdef __GLASGOW_HASKELL__
10 # include "Rts.h"
11 #endif
12
13 #include "HsBase.h"
14
15 #ifdef __GLASGOW_HASKELL__
16
17 void errorBelch2(const char*s, char *t)
18 {
19     errorBelch(s,t);
20 }
21
22 void debugBelch2(const char*s, char *t)
23 {
24     debugBelch(s,t);
25 }
26
27 #if defined(HAVE_LIBCHARSET)
28 #  include <libcharset.h>
29 #elif defined(HAVE_LANGINFO_H)
30 #  include <langinfo.h>
31 #endif
32
33 const char* localeEncoding(void)
34 {
35 #if defined(HAVE_LIBCHARSET)
36     return locale_charset();
37
38 #elif defined(HAVE_LANGINFO_H)
39     return nl_langinfo(CODESET);
40
41 #else
42 #warning Depending on the unportable behavior of GNU iconv due to absence of both libcharset and langinfo.h
43     /* GNU iconv accepts "" to mean the current locale's
44      * encoding. Warning: This isn't portable.
45      */
46     return "";
47 #endif
48 }
49
50 #endif /* __GLASGOW_HASKELL__ */