mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-14 05:16:18 +01:00
g_get_current_dir(): consult PWD first
Check if the current directory is the same as $PWD. This matches the behaviour of the get_current_dir_name() function in glibc. https://bugzilla.gnome.org/show_bug.cgi?id=705902
This commit is contained in:
parent
0f1579e62c
commit
a22f77739d
@ -2451,6 +2451,11 @@ g_path_get_dirname (const gchar *file_name)
|
|||||||
* The encoding of the returned string is system defined.
|
* The encoding of the returned string is system defined.
|
||||||
* On Windows, it is always UTF-8.
|
* 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
|
* Returns: the current directory
|
||||||
*/
|
*/
|
||||||
gchar *
|
gchar *
|
||||||
@ -2476,10 +2481,17 @@ g_get_current_dir (void)
|
|||||||
return dir;
|
return dir;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
const gchar *pwd;
|
||||||
gchar *buffer = NULL;
|
gchar *buffer = NULL;
|
||||||
gchar *dir = NULL;
|
gchar *dir = NULL;
|
||||||
static gulong max_len = 0;
|
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)
|
if (max_len == 0)
|
||||||
max_len = (G_PATH_LENGTH == -1) ? 2048 : G_PATH_LENGTH;
|
max_len = (G_PATH_LENGTH == -1) ? 2048 : G_PATH_LENGTH;
|
||||||
|
Loading…
Reference in New Issue
Block a user