From 57b3ddd7abc9bd33b9434a4d95ae68c6e2761af4 Mon Sep 17 00:00:00 2001 From: Gonzalo Paniagua Javier Date: Thu, 18 Nov 2010 12:29:06 -0500 Subject: [PATCH] Fix g_dir_open et al for windows. This was using the *A functiones instead of the *W ones and passing in UTF16. It was also opening and closing the directory just to check that it was there and then open it again !?. Fixes bug #645189. --- eglib/src/gdir-win32.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/eglib/src/gdir-win32.c b/eglib/src/gdir-win32.c index 839f0b131bc..28a42bc210a 100644 --- a/eglib/src/gdir-win32.c +++ b/eglib/src/gdir-win32.c @@ -51,46 +51,40 @@ g_dir_open (const gchar *path, guint flags, GError **error) g_return_val_if_fail (path != NULL, NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); - dir = g_new0 (GDir, 1); + dir = g_new0 (GDir, 1); path_utf16 = u8to16 (path); + path_utf16_search = g_malloc ((wcslen(path_utf16) + 3)*sizeof(gunichar2)); + wcscpy (path_utf16_search, path_utf16); + wcscat (path_utf16_search, L"\\*"); - dir->handle = FindFirstFile (path_utf16, &find_data); + dir->handle = FindFirstFileW (path_utf16_search, &find_data); if (dir->handle == INVALID_HANDLE_VALUE) { if (error) { gint err = errno; *error = g_error_new (G_LOG_DOMAIN, g_file_error_from_errno (err), strerror (err)); } - g_free (dir); + g_free (path_utf16_search); g_free (path_utf16); + g_free (dir); return NULL; } - - /* now get files */ - FindClose (dir->handle); - path_utf16_search = g_malloc ((wcslen(path_utf16) + 3)*sizeof(gunichar2)); - wcscpy (path_utf16_search, path_utf16); - wcscat (path_utf16_search, L"\\*"); - - dir->handle = FindFirstFile (path_utf16_search, &find_data); g_free (path_utf16_search); + g_free (path_utf16); while ((wcscmp (find_data.cFileName, L".") == 0) || (wcscmp (find_data.cFileName, L"..") == 0)) { - if (!FindNextFile (dir->handle, &find_data)) { + if (!FindNextFileW (dir->handle, &find_data)) { if (error) { gint err = errno; *error = g_error_new (G_LOG_DOMAIN, g_file_error_from_errno (err), strerror (err)); } g_free (dir); - g_free (path_utf16); return NULL; } } dir->current = NULL; dir->next = u16to8 (find_data.cFileName); - - g_free (path_utf16); return dir; } @@ -113,7 +107,7 @@ g_dir_read_name (GDir *dir) dir->next = NULL; do { - if (!FindNextFile (dir->handle, &find_data)) { + if (!FindNextFileW (dir->handle, &find_data)) { dir->next = NULL; return dir->current; } -- 2.25.1