+/*< private >
+ * g_dir_open_with_errno:
+ * @path: the path to the directory you are interested in.
+ * @flags: Currently must be set to 0. Reserved for future use.
+ *
+ * Opens a directory for reading.
+ *
+ * This function is equivalent to g_dir_open() except in the error case,
+ * errno will be set accordingly.
+ *
+ * This is useful if you want to construct your own error message.
+ *
+ * Returns: a newly allocated #GDir on success, or %NULL on failure,
+ * with errno set accordingly.
+ *
+ * Since: 2.38
+ */
+GDir *
+g_dir_open_with_errno (const gchar *path,
+ guint flags)
+{
+ GDir dir;
+#ifdef G_OS_WIN32
+ gint saved_errno;
+ wchar_t *wpath;
+#endif
+
+ g_return_val_if_fail (path != NULL, NULL);
+
+#ifdef G_OS_WIN32
+ wpath = g_utf8_to_utf16 (path, -1, NULL, NULL, NULL);
+
+ g_return_val_if_fail (wpath != NULL, NULL);
+
+ dir.wdirp = _wopendir (wpath);
+ saved_errno = errno;
+ g_free (wpath);
+ errno = saved_errno;
+
+ if (dir.wdirp == NULL)
+ return NULL;
+#else
+ dir.dirp = opendir (path);
+
+ if (dir.dirp == NULL)
+ return NULL;
+#endif
+
+ return g_memdup (&dir, sizeof dir);
+}
+