[git] GnuPG - branch, master, updated. gnupg-2.1.10-147-g3e50236

by Andre Heinecke cvs at cvs.gnupg.org
Tue Jan 26 10:00:57 CET 2016


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "The GNU Privacy Guard".

The branch, master has been updated
       via  3e50236d4ecc3601b2641bf4273a0ff64bb5fdc4 (commit)
      from  b8bb16c6c08d3c2947f1ff67419b36eb203c5c1a (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 3e50236d4ecc3601b2641bf4273a0ff64bb5fdc4
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Tue Jan 26 09:53:42 2016 +0100

    gpgtar,w32: Fix gpgtar 8 bit encoding handling on W32
    
    * common/utf8conv.c (wchar_to_utf8): Factor code out to ...
    (wchar_to_cp): new.
    (utf8_to_wchar): Factor code out to ...
    (cp_to_wchar): new.
    (wchar_to_native): New.
    (native_to_wchar): New.
    * tools/gpgtar-create.c (fillup_entry_w32): Use native_to_wchar.
    (scan_directory): Use wchar_to_native.
    --
    
    Gpgtar needs to handle filenames in the local 8 bit encoding on
    Windows as it uses the 8 bit file io functions.
    
    GnuPG-bug-id: 1624, 1746
    
    Patch from bug 1624 modified to fit into GnuPG 2.1 by wk.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/common/utf8conv.c b/common/utf8conv.c
index a912b82..8a2cf8a 100644
--- a/common/utf8conv.c
+++ b/common/utf8conv.c
@@ -713,17 +713,17 @@ jnlib_iconv_close (jnlib_iconv_t cd)
 
 
 #ifdef HAVE_W32_SYSTEM
-/* Return a malloced string encoded in UTF-8 from the wide char input
+/* Return a malloced string encoded for CODEPAGE from the wide char input
    string STRING.  Caller must free this value.  Returns NULL and sets
    ERRNO on failure.  Calling this function with STRING set to NULL is
    not defined.  */
-char *
-wchar_to_utf8 (const wchar_t *string)
+static char *
+wchar_to_cp (const wchar_t *string, unsigned int codepage)
 {
   int n;
   char *result;
 
-  n = WideCharToMultiByte (CP_UTF8, 0, string, -1, NULL, 0, NULL, NULL);
+  n = WideCharToMultiByte (codepage, 0, string, -1, NULL, 0, NULL, NULL);
   if (n < 0)
     {
       gpg_err_set_errno (EINVAL);
@@ -734,7 +734,7 @@ wchar_to_utf8 (const wchar_t *string)
   if (!result)
     return NULL;
 
-  n = WideCharToMultiByte (CP_UTF8, 0, string, -1, result, n, NULL, NULL);
+  n = WideCharToMultiByte (codepage, 0, string, -1, result, n, NULL, NULL);
   if (n < 0)
     {
       xfree (result);
@@ -745,18 +745,18 @@ wchar_to_utf8 (const wchar_t *string)
 }
 
 
-/* Return a malloced wide char string from an UTF-8 encoded input
+/* Return a malloced wide char string from a CODEPAGE encoded input
    string STRING.  Caller must free this value.  Returns NULL and sets
    ERRNO on failure.  Calling this function with STRING set to NULL is
    not defined.  */
-wchar_t *
-utf8_to_wchar (const char *string)
+static wchar_t *
+cp_to_wchar (const char *string, unsigned int codepage)
 {
   int n;
   size_t nbytes;
   wchar_t *result;
 
-  n = MultiByteToWideChar (CP_UTF8, 0, string, -1, NULL, 0);
+  n = MultiByteToWideChar (codepage, 0, string, -1, NULL, 0);
   if (n < 0)
     {
       gpg_err_set_errno (EINVAL);
@@ -773,7 +773,7 @@ utf8_to_wchar (const char *string)
   if (!result)
     return NULL;
 
-  n = MultiByteToWideChar (CP_UTF8, 0, string, -1, result, n);
+  n = MultiByteToWideChar (codepage, 0, string, -1, result, n);
   if (n < 0)
     {
       xfree (result);
@@ -782,4 +782,49 @@ utf8_to_wchar (const char *string)
     }
   return result;
 }
+
+
+/* Return a malloced string encoded in the active code page from the
+ * wide char input string STRING.  Caller must free this value.
+ * Returns NULL and sets ERRNO on failure.  Calling this function with
+ * STRING set to NULL is not defined.  */
+char *
+wchar_to_native (const wchar_t *string)
+{
+  return wchar_to_cp (string, CP_ACP);
+}
+
+
+/* Return a malloced wide char string from an UTF-8 encoded input
+ * string STRING.  Caller must free this value.  Returns NULL and sets
+ * ERRNO on failure.  Calling this function with STRING set to NULL is
+ * not defined.  */
+wchar_t *
+native_to_wchar (const char *string)
+{
+  return cp_to_wchar (string, CP_ACP);
+}
+
+
+/* Return a malloced string encoded in UTF-8 from the wide char input
+ * string STRING.  Caller must free this value.  Returns NULL and sets
+ * ERRNO on failure.  Calling this function with STRING set to NULL is
+ * not defined.  */
+char *
+wchar_to_utf8 (const wchar_t *string)
+{
+  return wchar_to_cp (string, CP_UTF8);
+}
+
+
+/* Return a malloced wide char string from an UTF-8 encoded input
+ * string STRING.  Caller must free this value.  Returns NULL and sets
+ * ERRNO on failure.  Calling this function with STRING set to NULL is
+ * not defined.  */
+wchar_t *
+utf8_to_wchar (const char *string)
+{
+  return cp_to_wchar (string, CP_UTF8);
+}
+
 #endif /*HAVE_W32_SYSTEM*/
diff --git a/common/utf8conv.h b/common/utf8conv.h
index ad7dbe9..def35de 100644
--- a/common/utf8conv.h
+++ b/common/utf8conv.h
@@ -48,6 +48,8 @@ size_t jnlib_iconv (jnlib_iconv_t cd, const char **inbuf, size_t *inbytesleft,
 int jnlib_iconv_close (jnlib_iconv_t cd);
 
 #ifdef HAVE_W32_SYSTEM
+char *wchar_to_native (const wchar_t *string);
+wchar_t *native_to_wchar (const char *string);
 char *wchar_to_utf8 (const wchar_t *string);
 wchar_t *utf8_to_wchar (const char *string);
 #endif /*HAVE_W32_SYSTEM*/
diff --git a/tools/gpgtar-create.c b/tools/gpgtar-create.c
index 2fd7019..968dca6 100644
--- a/tools/gpgtar-create.c
+++ b/tools/gpgtar-create.c
@@ -72,13 +72,13 @@ fillup_entry_w32 (tar_header_t hdr)
   for (p=hdr->name; *p; p++)
     if (*p == '/')
       *p = '\\';
-  wfname = utf8_to_wchar (hdr->name);
+  wfname = native_to_wchar (hdr->name);
   for (p=hdr->name; *p; p++)
     if (*p == '\\')
       *p = '/';
   if (!wfname)
     {
-      log_error ("error utf8-ing '%s': %s\n", hdr->name, w32_strerror (-1));
+      log_error ("error converting '%s': %s\n", hdr->name, w32_strerror (-1));
       return gpg_error_from_syserror ();
     }
   if (!GetFileAttributesExW (wfname, GetFileExInfoStandard, &fad))
@@ -299,7 +299,7 @@ scan_directory (const char *dname, scanctrl_t scanctrl)
     for (p=fname; *p; p++)
       if (*p == '/')
         *p = '\\';
-    wfname = utf8_to_wchar (fname);
+    wfname = native_to_wchar (fname);
     xfree (fname);
     if (!wfname)
       {
@@ -322,11 +322,11 @@ scan_directory (const char *dname, scanctrl_t scanctrl)
 
   do
     {
-      char *fname = wchar_to_utf8 (fi.cFileName);
+      char *fname = wchar_to_native (fi.cFileName);
       if (!fname)
         {
           err = gpg_error_from_syserror ();
-          log_error ("error utf8-ing filename: %s\n", w32_strerror (-1));
+          log_error ("error converting filename: %s\n", w32_strerror (-1));
           break;
         }
       for (p=fname; *p; p++)

-----------------------------------------------------------------------

Summary of changes:
 common/utf8conv.c     | 65 +++++++++++++++++++++++++++++++++++++++++++--------
 common/utf8conv.h     |  2 ++
 tools/gpgtar-create.c | 10 ++++----
 3 files changed, 62 insertions(+), 15 deletions(-)


hooks/post-receive
-- 
The GNU Privacy Guard
http://git.gnupg.org




More information about the Gnupg-commits mailing list