-DIR*
-g_win32_opendir (const char *dirname)
-{
- DIR *result;
- gchar *mask;
- guint k;
-
- g_return_val_if_fail (dirname != NULL, NULL);
-
- result = g_new0 (DIR, 1);
- result->find_file_data = g_new0 (WIN32_FIND_DATA, 1);
- result->dir_name = g_strdup (dirname);
-
- k = strlen (result->dir_name);
- if (k && result->dir_name[k - 1] == '\\')
- {
- result->dir_name[k - 1] = '\0';
- }
- mask = g_strdup_printf ("%s\\*", result->dir_name);
-
- result->find_file_handle = (guint) FindFirstFile (mask,
- (LPWIN32_FIND_DATA) result->find_file_data);
- g_free (mask);
-
- if (result->find_file_handle == (guint) INVALID_HANDLE_VALUE)
- {
- int error = GetLastError ();
-
- g_free (result->dir_name);
- g_free (result->find_file_data);
- g_free (result);
- switch (error)
- {
- default:
- errno = EIO;
- return NULL;
- }
- }
- result->just_opened = TRUE;
-
- return result;
-}
-
-struct dirent*
-g_win32_readdir (DIR *dir)
-{
- gchar *basename;
-
- g_return_val_if_fail (dir != NULL, NULL);
-
- if (dir->just_opened)
- dir->just_opened = FALSE;
- else
- {
- if (!FindNextFile ((HANDLE) dir->find_file_handle,
- (LPWIN32_FIND_DATA) dir->find_file_data))
- {
- int error = GetLastError ();
-
- switch (error)
- {
- case ERROR_NO_MORE_FILES:
- return NULL;
- default:
- errno = EIO;
- return NULL;
- }
- }
- }
-
- basename = g_path_get_basename (((LPWIN32_FIND_DATA) dir->find_file_data)->cFileName);
-
- strcpy (dir->readdir_result.d_name, basename);
-
- g_free (basename);
-
- return &dir->readdir_result;
-}
-
-void
-g_win32_rewinddir (DIR *dir)
-{
- gchar *mask;
-
- g_return_if_fail (dir != NULL);
-
- if (!FindClose ((HANDLE) dir->find_file_handle))
- g_warning ("gwin_rewinddir(): FindClose() failed\n");
-
- mask = g_strdup_printf ("%s\\*", dir->dir_name);
- dir->find_file_handle = (guint) FindFirstFile (mask,
- (LPWIN32_FIND_DATA) dir->find_file_data);
- g_free (mask);
-
- if (dir->find_file_handle == (guint) INVALID_HANDLE_VALUE)
- {
- int error = GetLastError ();
-
- switch (error)
- {
- default:
- errno = EIO;
- return;
- }
- }
- dir->just_opened = TRUE;
-}
-
-gint
-g_win32_closedir (DIR *dir)
-{
- g_return_val_if_fail (dir != NULL, -1);
-
- if (!FindClose ((HANDLE) dir->find_file_handle))
- {
- int error = GetLastError ();
-
- switch (error)
- {
- default:
- errno = EIO; return -1;
- }
- }
-
- g_free (dir->dir_name);
- g_free (dir->find_file_data);
- g_free (dir);
-
- return 0;
-}