diff options
author | Werner Koch <[email protected]> | 2007-06-06 18:12:30 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2007-06-06 18:12:30 +0000 |
commit | 2c9791db555cc571eaedfa71444da05454bd052a (patch) | |
tree | 9566d22f85e562e0c7b35dacc1697c9a58fcff1a /jnlib/utf8conv.c | |
parent | Print passphrase encoding info only in PEM mode. (diff) | |
download | gnupg-2c9791db555cc571eaedfa71444da05454bd052a.tar.gz gnupg-2c9791db555cc571eaedfa71444da05454bd052a.zip |
First steps towards supporting W32.
This is mainly source code reorganization.
Update gnulib.
g10/ does currently not build.
Diffstat (limited to 'jnlib/utf8conv.c')
-rw-r--r-- | jnlib/utf8conv.c | 57 |
1 files changed, 56 insertions, 1 deletions
diff --git a/jnlib/utf8conv.c b/jnlib/utf8conv.c index d7c0d44ba..90a319984 100644 --- a/jnlib/utf8conv.c +++ b/jnlib/utf8conv.c @@ -29,10 +29,13 @@ #include <langinfo.h> #endif #include <errno.h> -#include <iconv.h> +#ifndef HAVE_W32_SYSTEM +# include <iconv.h> +#endif #include "libjnlib-config.h" #include "stringhelp.h" +#include "dynload.h" #include "utf8conv.h" #ifndef MB_LEN_MAX @@ -45,6 +48,58 @@ static int no_translation; /* Set to true if we let simply pass through. */ static int use_iconv; /* iconv comversion fucntions required. */ +/* Under W32 we dlopen the iconv dll and don't require any iconv + related headers at all. However we need to define some stuff. */ +#ifdef HAVE_W32_SYSTEM +typedef void *iconv_t; +#ifndef ICONV_CONST +#define ICONV_CONST const +#endif +static iconv_t (* __stdcall iconv_open) (const char *tocode, + const char *fromcode); +static size_t (* __stdcall iconv) (iconv_t cd, + const char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft); +static int (* __stdcall iconv_close) (iconv_t cd); + +static int +load_libiconv (void) +{ + static int done; + + if (!done) + { + void *handle; + + done = 1; /* Do it right now because we might get called recursivly + through gettext. */ + + handle = dlopen ("iconv.dll", RTLD_LAZY); + if (handle) + { + iconv_open = dlsym (handle, "libiconv_open"); + if (iconv_open) + iconv = dlsym (handle, "libiconv"); + if (iconv) + iconv_close = dlsym (handle, "libiconv_close"); + } + if (!handle || !iconv_close) + { + log_info (_("error loading `%s': %s\n"), + "iconv.dll", dlerror ()); + log_info (_("please see http://www.gnupg.org/download/iconv.html " + "for more information\n")); + iconv_open = NULL; + iconv = NULL; + iconv_close = NULL; + if (handle) + dlclose (handle); + } + } + return iconv_open? 0: -1; +} +#endif /*HAVE_W32_SYSTEM*/ + /* Error handler for iconv failures. This is needed to not clutter the output with repeated diagnostics about a missing conversion. */ |