X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Ficonv_encode_wchar.c;h=a09b530353641836e39517555b8273c19a87034c;hp=cf0a5f6e4b62c7c8137ce92fc8031eedf10d08a0;hb=96c6e58f286787106e4a7b3bb3900a36051968d6;hpb=ee6ab2ee3a9ee1a8c65d7272ec7fba1d886f5af0 diff --git a/src/iconv_encode_wchar.c b/src/iconv_encode_wchar.c index cf0a5f6..a09b530 100644 --- a/src/iconv_encode_wchar.c +++ b/src/iconv_encode_wchar.c @@ -20,8 +20,6 @@ #endif #include -#include -#include #include "iconv-p.h" struct encoder_data @@ -67,6 +65,43 @@ yaz_iconv_encoder_t yaz_wchar_encoder(const char *tocode, return 0; } +#if HAVE_WCHAR_H +static unsigned long read_wchar_t(yaz_iconv_t cd, yaz_iconv_decoder_t d, + unsigned char *inp, + size_t inbytesleft, size_t *no_read) +{ + unsigned long x = 0; + + if (inbytesleft < sizeof(wchar_t)) + { + yaz_iconv_set_errno(cd, YAZ_ICONV_EINVAL); /* incomplete input */ + *no_read = 0; + } + else + { + wchar_t wch; + memcpy(&wch, inp, sizeof(wch)); + x = wch; + *no_read = sizeof(wch); + } + return x; +} +#endif + +yaz_iconv_decoder_t yaz_wchar_decoder(const char *fromcode, + yaz_iconv_decoder_t d) + +{ +#if HAVE_WCHAR_H + if (!yaz_matchstr(fromcode, "wchar_t")) + { + d->read_handle = read_wchar_t; + return d; + } +#endif + return 0; +} + /* * Local variables: