remaining gnupg changes for Android support

Abel Luck abel at guardianproject.info
Thu Dec 13 14:39:25 CET 2012


Werner Koch:
> Here we go:
>

This commit works! Sorry for the huge delay, I applied it months ago and
forgot to let you know.

Could we get it merged?

Thanks ~abel

>>From a1fa77e34574b309b20fa2b1ef8be5d56e59c66f Mon Sep 17 00:00:00 2001
> From: Werner Koch <wk at gnupg.org>
> Date: Mon, 12 Nov 2012 15:18:49 +0100
> Subject: [PATCH] utf8conv.c: Add hacks for Android.
> 
> * common/utf8conv.c [HAVE_ANDROID_SYSTEM]: Do not include iconv.h.
> (iconv_open, iconv_close, load_libiconv) [HAVE_ANDROID_SYSTEM]: New
> dummy functions.
> (set_native_charset) [HAVE_ANDROID_SYSTEM]: Force use of "utf-8".
> (jnlib_iconv_open) [HAVE_ANDROID_SYSTEM]: Act the same as under W32.
> (jnlib_iconv) [HAVE_ANDROID_SYSTEM]: Ditto.
> (jnlib_iconv_close) [HAVE_ANDROID_SYSTEM]: Ditto.
> --
> 
> Co-authored-by: Hans of Guardian <hans at guardianproject.info>
> ---
>  common/utf8conv.c |   69 ++++++++++++++++++++++++++++++++++++++++++----------
>  1 files changed, 55 insertions(+), 14 deletions(-)
> 
> diff --git a/common/utf8conv.c b/common/utf8conv.c
> index 1d64933..a45bb63 100644
> --- a/common/utf8conv.c
> +++ b/common/utf8conv.c
> @@ -38,7 +38,7 @@
>  #include <langinfo.h>
>  #endif
>  #include <errno.h>
> -#ifndef HAVE_W32_SYSTEM
> +#if !defined HAVE_W32_SYSTEM && !defined HAVE_ANDROID_SYSTEM
>  # include <iconv.h>
>  #endif
>  
> @@ -56,9 +56,48 @@ static int no_translation;     /* Set to true if we let simply pass through. */
>  static int use_iconv;          /* iconv comversion fucntions required. */
>  
>  
> +#ifdef HAVE_ANDROID_SYSTEM
> +/* Fake stuff to get things building.  */
> +typedef void *iconv_t;
> +#define ICONV_CONST
> +
> +static iconv_t
> +iconv_open (const char *tocode, const char *fromcode)
> +{
> +  (void)tocode;
> +  (void)fromcode;
> +  return (iconv_t)(-1);
> +}
> +
> +static size_t
> +iconv (iconv_t cd, char **inbuf, size_t *inbytesleft,
> +       char **outbuf, size_t *outbytesleft)
> +{
> +  (void)cd;
> +  (void)inbuf;
> +  (void)inbytesleft;
> +  (void)outbuf;
> +  (void)outbytesleft;
> +  return (size_t)(0);
> +}
> +
> +static int
> +iconv_close (iconv_t cd)
> +{
> +  (void)cd;
> +  return 0;
> +}
> +
> +
> +static int
> +load_libiconv (void)
> +{
> +  return -1;
> +}
> +
> +#elif defined HAVE_W32_SYSTEM
>  /* 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
> @@ -170,7 +209,9 @@ set_native_charset (const char *newset)
>  
>    if (!newset)
>      {
> -#ifdef HAVE_W32_SYSTEM
> +#ifdef HAVE_ANDROID_SYSTEM
> +      newset = "utf-8";
> +#elif defined HAVE_W32_SYSTEM
>        static char codepage[30];
>        unsigned int cpno;
>        const char *aliases;
> @@ -218,7 +259,7 @@ set_native_charset (const char *newset)
>              }
>          }
>  
> -#else /*!HAVE_W32_SYSTEM*/
> +#else /*!HAVE_W32_SYSTEM && !HAVE_ANDROID_SYSTEM*/
>  
>  #ifdef HAVE_LANGINFO_CODESET
>        newset = nl_langinfo (CODESET);
> @@ -252,7 +293,7 @@ set_native_charset (const char *newset)
>          }
>        newset = codepage;
>  #endif /*!HAVE_LANGINFO_CODESET*/
> -#endif /*!HAVE_W32_SYSTEM*/
> +#endif /*!HAVE_W32_SYSTEM && !HAVE_ANDROID_SYSTEM*/
>      }
>  
>    full_newset = newset;
> @@ -291,10 +332,10 @@ set_native_charset (const char *newset)
>      {
>        iconv_t cd;
>  
> -#ifdef HAVE_W32_SYSTEM
> +#if defined HAVE_W32_SYSTEM || defined HAVE_ANDROID_SYSTEM
>        if (load_libiconv ())
>          return -1;
> -#endif /*HAVE_W32_SYSTEM*/
> +#endif /*HAVE_W32_SYSTEM || HAVE_ANDROID_SYSTEM*/
>  
>        cd = iconv_open (full_newset, "utf-8");
>        if (cd == (iconv_t)-1)
> @@ -717,10 +758,10 @@ utf8_to_native (const char *string, size_t length, int delim)
>  jnlib_iconv_t
>  jnlib_iconv_open (const char *tocode, const char *fromcode)
>  {
> -#ifdef HAVE_W32_SYSTEM
> +#if defined HAVE_W32_SYSTEM || defined HAVE_ANDROID_SYSTEM
>    if (load_libiconv ())
>      return (jnlib_iconv_t)(-1);
> -#endif /*HAVE_W32_SYSTEM*/
> +#endif /*HAVE_W32_SYSTEM || HAVE_ANDROID_SYSTEM*/
>  
>    return (jnlib_iconv_t)iconv_open (tocode, fromcode);
>  }
> @@ -734,10 +775,10 @@ jnlib_iconv (jnlib_iconv_t cd,
>               char **outbuf, size_t *outbytesleft)
>  {
>  
> -#ifdef HAVE_W32_SYSTEM
> +#if defined HAVE_W32_SYSTEM || defined HAVE_ANDROID_SYSTEM
>    if (load_libiconv ())
>      return 0;
> -#endif /*HAVE_W32_SYSTEM*/
> +#endif /*HAVE_W32_SYSTEM || HAVE_ANDROID_SYSTEM*/
>  
>    return iconv ((iconv_t)cd, (char**)inbuf, inbytesleft, outbuf, outbytesleft);
>  }
> @@ -747,10 +788,10 @@ jnlib_iconv (jnlib_iconv_t cd,
>  int
>  jnlib_iconv_close (jnlib_iconv_t cd)
>  {
> -#ifdef HAVE_W32_SYSTEM
> +#if defined HAVE_W32_SYSTEM || defined HAVE_ANDROID_SYSTEM
>    if (load_libiconv ())
>      return 0;
> -#endif /*HAVE_W32_SYSTEM*/
> +#endif /*HAVE_W32_SYSTEM || HAVE_ANDROID_SYSTEM*/
>  
>    return iconv_close ((iconv_t)cd);
>  }
> @@ -826,4 +867,4 @@ utf8_to_wchar (const char *string)
>      }
>    return result;
>  }
> -#endif /*HAVE_W32_SYSTEM*/
> +#endif /*HAVE_W32_SYSTEM || HAVE_ANDROID_SYSTEM*/
> 




More information about the Gnupg-devel mailing list