Commit ae9d9686 authored by Tor Lillqvist's avatar Tor Lillqvist Committed by Tor Lillqvist

Use GetCurrentDirectory() directly for simpler buffer length management. I

2004-12-30  Tor Lillqvist  <tml@iki.fi>

	* glib/gutils.c (g_get_current_dir): Use GetCurrentDirectory()
	directly for simpler buffer length management. I don't trust
	getcwd() getting it right all the time.
parent 647aba60
2004-12-30 Tor Lillqvist <tml@iki.fi>
* glib/gutils.c (g_get_current_dir): Use GetCurrentDirectory()
directly for simpler buffer length management. I don't trust
getcwd() getting it right all the time.
2004-12-30 Matthias Clasen <mclasen@redhat.com>
* glib/gfileutils.c (g_file_test): Typo fix.
......
2004-12-30 Tor Lillqvist <tml@iki.fi>
* glib/gutils.c (g_get_current_dir): Use GetCurrentDirectory()
directly for simpler buffer length management. I don't trust
getcwd() getting it right all the time.
2004-12-30 Matthias Clasen <mclasen@redhat.com>
* glib/gfileutils.c (g_file_test): Typo fix.
......
2004-12-30 Tor Lillqvist <tml@iki.fi>
* glib/gutils.c (g_get_current_dir): Use GetCurrentDirectory()
directly for simpler buffer length management. I don't trust
getcwd() getting it right all the time.
2004-12-30 Matthias Clasen <mclasen@redhat.com>
* glib/gfileutils.c (g_file_test): Typo fix.
......
2004-12-30 Tor Lillqvist <tml@iki.fi>
* glib/gutils.c (g_get_current_dir): Use GetCurrentDirectory()
directly for simpler buffer length management. I don't trust
getcwd() getting it right all the time.
2004-12-30 Matthias Clasen <mclasen@redhat.com>
* glib/gfileutils.c (g_file_test): Typo fix.
......
2004-12-30 Tor Lillqvist <tml@iki.fi>
* glib/gutils.c (g_get_current_dir): Use GetCurrentDirectory()
directly for simpler buffer length management. I don't trust
getcwd() getting it right all the time.
2004-12-30 Matthias Clasen <mclasen@redhat.com>
* glib/gfileutils.c (g_file_test): Typo fix.
......
......@@ -718,35 +718,51 @@ g_path_get_dirname (const gchar *file_name)
gchar*
g_get_current_dir (void)
{
gchar *buffer = NULL;
#ifdef G_OS_WIN32
gchar *dir = NULL;
static gulong max_len = 0;
if (max_len == 0)
max_len = (G_PATH_LENGTH == -1) ? 2048 : G_PATH_LENGTH;
#ifdef G_OS_WIN32
if (G_WIN32_HAVE_WIDECHAR_API ())
{
wchar_t *wdir = _wgetcwd (NULL, max_len);
if (wdir)
wchar_t dummy[2], *wdir;
int len;
len = GetCurrentDirectoryW (2, dummy);
wdir = g_new (wchar_t, len);
if (GetCurrentDirectoryW (len, wdir) == len - 1)
dir = g_utf16_to_utf8 (wdir, -1, NULL, NULL, NULL);
else
dir = g_strdup (G_DIR_SEPARATOR_S);
free (wdir);
g_free (wdir);
}
else
{
char *cpdir = getcwd (NULL, max_len);
if (cpdir)
gchar dummy[2], *cpdir;
int len;
len = GetCurrentDirectoryA (2, dummy);
cpdir = g_new (gchar, len);
if (GetCurrentDirectoryA (len, cpdir) == len - 1)
dir = g_locale_to_utf8 (cpdir, -1, NULL, NULL, NULL);
else
dir = g_strdup (G_DIR_SEPARATOR_S);
free (cpdir);
g_free (cpdir);
}
if (dir == NULL)
dir = g_strdup ("\\");
return dir;
#else
gchar *buffer = NULL;
gchar *dir = NULL;
static gulong max_len = 0;
if (max_len == 0)
max_len = (G_PATH_LENGTH == -1) ? 2048 : G_PATH_LENGTH;
/* We don't use getcwd(3) on SUNOS, because, it does a popen("pwd")
* and, if that wasn't bad enough, hangs in doing so.
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment