iconv.h
Go to the documentation of this file.
1 #ifndef NVIM_ICONV_H
2 #define NVIM_ICONV_H
3 
4 // iconv can be linked at compile-time as well as loaded at runtime. In the
5 // latter case, some function pointers need to be initialized after loading
6 // the library (see `iconv_enabled()` in mbyte.c). These function pointers
7 // are stored in globals.h. Since globals.h includes iconv.h to get the
8 // definition of USE_ICONV, we can't include it from iconv.h. One way to
9 // solve this conundrum would be perhaps to let cmake decide the value of
10 // USE_ICONV, or to put the USE_ICONV definition in config.h.in directly. As
11 // it stands, globals.h needs to be included alongside iconv.h.
12 
13 #include "auto/config.h"
14 
15 // Use iconv() when it's available, either by linking to the library at
16 // compile time or by loading it at runtime.
17 #if (defined(HAVE_ICONV_H) && defined(HAVE_ICONV)) || defined(DYNAMIC_ICONV)
18 # define USE_ICONV
19 #endif
20 
21 // If we don't have the actual iconv header files present but USE_ICONV was
22 // defined, we provide a type shim (pull in errno.h and define iconv_t).
23 // This enables us to still load and use iconv dynamically at runtime.
24 #ifdef USE_ICONV
25 # include <errno.h>
26 # ifdef HAVE_ICONV_H
27 # include <iconv.h>
28 # else
29 typedef void *iconv_t;
30 # endif
31 #endif
32 
33 // define some missing constants if necessary
34 # ifdef USE_ICONV
35 # ifndef EILSEQ
36 # define EILSEQ 123
37 # endif
38 # ifdef DYNAMIC_ICONV
39 // on win32 iconv.dll is dynamically loaded
40 # define ICONV_ERRNO (*iconv_errno())
41 # define ICONV_E2BIG 7
42 # define ICONV_EINVAL 22
43 # define ICONV_EILSEQ 42
44 # else
45 # define ICONV_ERRNO errno
46 # define ICONV_E2BIG E2BIG
47 # define ICONV_EINVAL EINVAL
48 # define ICONV_EILSEQ EILSEQ
49 # endif
50 # endif
51 
52 #endif // NVIM_ICONV_H