diff --git a/thunar/thunar-util.c b/thunar/thunar-util.c index b49a954..91be738 100644 --- a/thunar/thunar-util.c +++ b/thunar/thunar-util.c @@ -404,20 +404,33 @@ thunar_util_change_working_directory (const gchar *new_directory) _thunar_return_val_if_fail (new_directory != NULL && *new_directory != '\0', NULL); + /* try to determine the current working directory */ +#if defined(G_PLATFORM_WIN32) /* allocate a path buffer for the old working directory */ old_directory = g_malloc0 (sizeof (gchar) * MAXPATHLEN); - /* try to determine the current working directory */ -#ifdef G_PLATFORM_WIN32 if (_getcwd (old_directory, MAXPATHLEN) == NULL) -#else - if (getcwd (old_directory, MAXPATHLEN) == NULL) + { + /* working directory couldn't be determined, reset the buffer */ + g_free (old_directory); + old_directory = NULL; + } +#elif defined(_GNU_SOURCE) + old_directory = get_current_dir_name(); +#else +#ifndef MAXPATHLEN +#define MAXPATHLEN 4096 #endif + /* allocate a path buffer for the old working directory */ + old_directory = g_malloc (sizeof (gchar) * MAXPATHLEN); + + if (getcwd (old_directory, MAXPATHLEN) == NULL) { /* working directory couldn't be determined, reset the buffer */ g_free (old_directory); old_directory = NULL; } +#endif /* try switching to the new working directory */ #ifdef G_PLATFORM_WIN32