gnucash maint: Integrate Windows gzopen differences so that only one ifdef is needed.
John Ralls
jralls at code.gnucash.org
Sat Mar 5 19:21:24 EST 2022
Updated via https://github.com/Gnucash/gnucash/commit/916caa25 (commit)
from https://github.com/Gnucash/gnucash/commit/f58279ab (commit)
commit 916caa25f223a36cca4a9d88ee1684ff52a777e1
Author: John Ralls <jralls at ceridwen.us>
Date: Fri Mar 4 16:49:36 2022 -0800
Integrate Windows gzopen differences so that only one ifdef is needed.
Clarifies code.
diff --git a/libgnucash/backend/xml/io-gncxml-v2.cpp b/libgnucash/backend/xml/io-gncxml-v2.cpp
index 5b48c2d02..9b746fdfe 100644
--- a/libgnucash/backend/xml/io-gncxml-v2.cpp
+++ b/libgnucash/backend/xml/io-gncxml-v2.cpp
@@ -1386,10 +1386,10 @@ gnc_book_write_accounts_to_xml_filehandle_v2 (QofBackend* qof_be, QofBook* book,
return success;
}
-#ifdef G_OS_WIN32
static inline gzFile
-gzopen_win32 (const char* filename, const char* perms)
+do_gzopen (const char* filename, const char* perms)
{
+#ifdef G_OS_WIN32
gzFile file;
char* new_perms = nullptr;
char* conv_name = g_win32_locale_filename_from_utf8 (filename);
@@ -1410,8 +1410,10 @@ gzopen_win32 (const char* filename, const char* perms)
g_free (new_perms);
g_free (conv_name);
return file;
-}
+#else
+ return gzopen (filename, perms);
#endif
+}
constexpr uint32_t BUFLEN{4096};
@@ -1497,11 +1499,7 @@ gz_thread_func (gz_thread_params_t* params)
gint gzval;
bool success = true;
-#ifdef G_OS_WIN32
- auto file = gzopen_win32 (params->filename, params->perms);
-#else /* !G_OS_WIN32 */
- auto file = gzopen (params->filename, params->perms);
-#endif /* G_OS_WIN32 */
+ auto file = do_gzopen (params->filename, params->perms);
if (!file)
{
@@ -1570,6 +1568,7 @@ try_gz_open (const char* filename, const char* perms, gboolean compress,
close(filedes[0]);
close(filedes[1]);
}
+
return std::pair<FILE*, GThread*>(g_fopen (filename, perms),
nullptr);
}
@@ -1594,7 +1593,6 @@ try_gz_open (const char* filename, const char* perms, gboolean compress,
close (filedes[0]);
close (filedes[1]);
file = g_fopen (filename, perms);
-
}
else
{
@@ -1701,20 +1699,8 @@ gnc_is_xml_data_file_v2 (const gchar* name, gboolean* with_encoding)
char first_chunk[256];
int num_read;
-#ifdef G_OS_WIN32
- {
- gchar* conv_name = g_win32_locale_filename_from_utf8 (name);
- if (!conv_name)
- g_warning ("Could not convert '%s' to system codepage", name);
- else
- {
- file = gzopen (conv_name, "rb");
- g_free (conv_name);
- }
- }
-#else
- file = gzopen (name, "r");
-#endif
+ file = do_gzopen (name, "r");
+
if (file == NULL)
return GNC_BOOK_NOT_OURS;
Summary of changes:
libgnucash/backend/xml/io-gncxml-v2.cpp | 32 +++++++++-----------------------
1 file changed, 9 insertions(+), 23 deletions(-)
More information about the gnucash-changes
mailing list