1 //
2 //  Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
3 //
4 //  Distributed under the Boost Software License, Version 1.0. (See
5 //  accompanying file LICENSE_1_0.txt or copy at
6 //  http://www.boost.org/LICENSE_1_0.txt)
7 //
8 #ifndef BOOST_LOCALE_ICONV_FIXER_HPP
9 #define BOOST_LOCALE_ICONV_FIXER_HPP
10 
11 #include <iconv.h>
12 
13 namespace boost {
14     namespace locale {
15 #if defined(__ICONV_F_HIDE_INVALID) && defined(__FreeBSD__)
16         extern "C" {
17             typedef size_t (*const_iconv_ptr_type)(iconv_t d,char const **in,size_t *insize,char **out,size_t *outsize,uint32_t,size_t *);
18             typedef size_t (*nonconst_iconv_ptr_type)(iconv_t d,char **in,size_t *insize,char **out,size_t *outsize,uint32_t,size_t *);
19         }
do_iconv(const_iconv_ptr_type ptr,iconv_t d,char ** in,size_t * insize,char ** out,size_t * outsize)20         inline size_t do_iconv(const_iconv_ptr_type ptr,iconv_t d,char **in,size_t *insize,char **out,size_t *outsize)
21         {
22             char const **rin = const_cast<char const **>(in);
23             return ptr(d,rin,insize,out,outsize,__ICONV_F_HIDE_INVALID,0);
24         }
do_iconv(nonconst_iconv_ptr_type ptr,iconv_t d,char ** in,size_t * insize,char ** out,size_t * outsize)25         inline size_t do_iconv(nonconst_iconv_ptr_type ptr,iconv_t d,char **in,size_t *insize,char **out,size_t *outsize)
26         {
27             return ptr(d,in,insize,out,outsize,__ICONV_F_HIDE_INVALID,0);
28         }
call_iconv(iconv_t d,char ** in,size_t * insize,char ** out,size_t * outsize)29         inline size_t call_iconv(iconv_t d,char **in,size_t *insize,char **out,size_t *outsize)
30         {
31             char const **rin = const_cast<char const **>(in);
32             return do_iconv(__iconv, d, in,insize,out,outsize);
33         }
34 #else
35         extern "C" {
36             typedef size_t (*gnu_iconv_ptr_type)(iconv_t d,char const **in,size_t *insize,char **out,size_t *outsize);
37             typedef size_t (*posix_iconv_ptr_type)(iconv_t d,char **in,size_t *insize,char **out,size_t *outsize);
38         }
39         inline size_t do_iconv(gnu_iconv_ptr_type ptr,iconv_t d,char **in,size_t *insize,char **out,size_t *outsize)
40         {
41             char const **rin = const_cast<char const **>(in);
42             return ptr(d,rin,insize,out,outsize);
43         }
44         inline size_t do_iconv(posix_iconv_ptr_type ptr,iconv_t d,char **in,size_t *insize,char **out,size_t *outsize)
45         {
46             return ptr(d,in,insize,out,outsize);
47         }
48         inline size_t call_iconv(iconv_t d,char **in,size_t *insize,char **out,size_t *outsize)
49         {
50             return do_iconv( iconv, d, in,insize,out,outsize);
51         }
52 #endif
53 
54     } // locale
55 } // boost
56 
57 #endif
58 // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
59