$OpenBSD: patch-glib_gfileutils_c,v 1.1 2014/01/03 16:01:53 ajacoutot Exp $

From a22f77739dd4ec911d7bdc0f0fc61314e5f9f1cf Mon Sep 17 00:00:00 2001
From: Ryan Lortie <desrt@desrt.ca>
Date: Sun, 08 Dec 2013 23:18:16 +0000
Subject: g_get_current_dir(): consult PWD first

--- glib/gfileutils.c.orig	Tue Nov 12 06:30:22 2013
+++ glib/gfileutils.c	Fri Jan  3 16:52:38 2014
@@ -2469,6 +2469,11 @@ g_path_get_dirname (const gchar *file_name)
  * The encoding of the returned string is system defined.
  * On Windows, it is always UTF-8.
  *
+ * Since GLib 2.40, this function will return the value of the "PWD"
+ * environment variable if it is set and it happens to be the same as
+ * the current directory.  This can make a difference in the case that
+ * the current directory is the target of a symbolic link.
+ *
  * Returns: the current directory
  */
 gchar *
@@ -2494,10 +2499,17 @@ g_get_current_dir (void)
   return dir;
 
 #else
-
+  const gchar *pwd;
   gchar *buffer = NULL;
   gchar *dir = NULL;
   static gulong max_len = 0;
+  struct stat pwdbuf, dotbuf;
+
+  pwd = g_getenv ("PWD");
+  if (pwd != NULL &&
+      g_stat (".", &dotbuf) == 0 && g_stat (pwd, &pwdbuf) == 0 &&
+      dotbuf.st_dev == pwdbuf.st_dev && dotbuf.st_ino == pwdbuf.st_ino)
+    return g_strdup (pwd);
 
   if (max_len == 0)
     max_len = (G_PATH_LENGTH == -1) ? 2048 : G_PATH_LENGTH;
