aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/sysutils.c49
-rw-r--r--common/util.h4
2 files changed, 52 insertions, 1 deletions
diff --git a/common/sysutils.c b/common/sysutils.c
index df62aa254..520aa56e4 100644
--- a/common/sysutils.c
+++ b/common/sysutils.c
@@ -1219,6 +1219,55 @@ gnupg_stat (const char *name, struct stat *statbuf)
#endif /*HAVE_STAT*/
+/* Wrapper around fopen for the cases where we have not yet switched
+ * to es_fopen. Note that for convenience the prototype is in util.h */
+FILE *
+gnupg_fopen (const char *fname, const char *mode)
+{
+#ifdef HAVE_W32_SYSTEM
+ if (any8bitchar (fname))
+ {
+ wchar_t *wfname;
+ const wchar_t *wmode;
+ wchar_t *wmodebuf = NULL;
+ FILE *ret;
+
+ wfname = utf8_to_wchar (fname);
+ if (!wfname)
+ return NULL;
+ if (!strcmp (mode, "r"))
+ wmode = L"r";
+ else if (!strcmp (mode, "rb"))
+ wmode = L"rb";
+ else if (!strcmp (mode, "w"))
+ wmode = L"w";
+ else if (!strcmp (mode, "wb"))
+ wmode = L"wb";
+ else
+ {
+ wmodebuf = utf8_to_wchar (mode);
+ if (!wmodebuf)
+ {
+ xfree (wfname);
+ return NULL;
+ }
+ wmode = wmodebuf;
+ }
+ ret = _wfopen (wfname, wmode);
+ xfree (wfname);
+ xfree (wmodebuf);
+ return ret;
+ }
+ else
+ return fopen (fname, mode);
+
+#else /*Unix*/
+ return fopen (fname, mode);
+#endif /*Unix*/
+}
+
+
+
/* A wrapper around open to handle Unicode file names under Windows. */
int
gnupg_open (const char *name, int flags, unsigned int mode)
diff --git a/common/util.h b/common/util.h
index 4d61bc0ea..75cdee0b4 100644
--- a/common/util.h
+++ b/common/util.h
@@ -142,7 +142,6 @@ ssize_t read_line (FILE *fp,
char **addr_of_buffer, size_t *length_of_buffer,
size_t *max_length);
-
/*-- b64enc.c and b64dec.c --*/
struct b64state
{
@@ -287,6 +286,9 @@ char *gnupg_get_help_string (const char *key, int only_current_locale);
/*-- localename.c --*/
const char *gnupg_messages_locale_name (void);
+/*-- sysutils.c --*/
+FILE *gnupg_fopen (const char *fname, const char *mode);
+
/*-- miscellaneous.c --*/
/* This function is called at startup to tell libgcrypt to use our own