/* Returns: a newly allocated #GDir on success, NULL on failure. If non-NULL, you must free the result with g_dir_close() when you are finished with it.  */
GDir* g_dir_open(const gchar *path, guint flags, GError **error)
/* Returns: a newly allocated #GDir on success, NULL on failure. If non-NULL, you must free the result with g_dir_close() when you are finished with it.  */
GDir* g_dir_open(const gchar *path, guint flags, GError **error)
{
  gint saved_errno;
  GDir *dir;
  dir = g_dir_open_with_errno (path, flags);
  if (dir == NULL)
    {
      gchar *utf8_path;
      saved_errno = errno;
      utf8_path = g_filename_to_utf8 (path, -1, NULL, NULL, NULL);
      g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (saved_errno),
                   _("Error opening directory '%s': %s"), utf8_path, g_strerror (saved_errno));
      g_free (utf8_path);
    }
  return dir;
}