[PATCH] UTF8 Filenames under Windows

Tobias tobias at radolfstrasse.de
Sun May 5 18:17:05 CEST 2013


As GnuPG’s command line does not support UTF 16 filenames, all filenames must be encoded in UTF8.
With Linux this just works fine, but the Windows Ascii API (CreateFileA) does not support accessing files using UTF8 paths. It just results in a File not found Error.

Attached is a patch for the GnuPG 1.4 branch, that converts all paths from UTF8 to UTF16 and pass them to Windows Wide API.

It should resolve the issue 1409.

Would be great if it would make into one of the next stable versions.

Thanks
Tobias



diff --git a/util/iobuf.c b/util/iobuf.c
index 384b966..aedff90 100644
--- a/util/iobuf.c
+++ b/util/iobuf.c
@@ -242,6 +242,7 @@ direct_open (const char *fname, const char *mode)
#ifdef HAVE_DOSISH_SYSTEM
     unsigned long da, cd, sm;
     HANDLE hfile;
+    unsigned short wPath[_MAX_PATH];

     /* Note, that we do not handle all mode combinations */

@@ -266,8 +267,9 @@ direct_open (const char *fname, const char *mode)
         cd = OPEN_EXISTING;
         sm = FILE_SHARE_READ;
     }
+    MultiByteToWideChar(CP_UTF8, 0, fname, -1, wPath, _MAX_PATH);

-    hfile = CreateFile (fname, da, sm, NULL, cd, FILE_ATTRIBUTE_NORMAL, NULL);
+    hfile = CreateFileW (wPath, da, sm, NULL, cd, FILE_ATTRIBUTE_NORMAL, NULL);
     return hfile;
#else
     int oflag;






More information about the Gnupg-devel mailing list