summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Lillqvist <tml@iki.fi>2004-12-30 17:48:23 +0000
committerTor Lillqvist <tml@src.gnome.org>2004-12-30 17:48:23 +0000
commitae9d96865d769a68064d20ccbb6911fbab2af2a1 (patch)
treee7f1aa30d202baac6bce399e12b47759cefc8f30
parent647aba60aa8ddc309e9035b538ce7982193fbf03 (diff)
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.
-rw-r--r--ChangeLog6
-rw-r--r--ChangeLog.pre-2-106
-rw-r--r--ChangeLog.pre-2-126
-rw-r--r--ChangeLog.pre-2-66
-rw-r--r--ChangeLog.pre-2-86
-rw-r--r--glib/gutils.c48
6 files changed, 62 insertions, 16 deletions
diff --git a/ChangeLog b/ChangeLog
index 7890b77b3..7e3b1bd76 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+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.
diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10
index 7890b77b3..7e3b1bd76 100644
--- a/ChangeLog.pre-2-10
+++ b/ChangeLog.pre-2-10
@@ -1,3 +1,9 @@
+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.
diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12
index 7890b77b3..7e3b1bd76 100644
--- a/ChangeLog.pre-2-12
+++ b/ChangeLog.pre-2-12
@@ -1,3 +1,9 @@
+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.
diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6
index 7890b77b3..7e3b1bd76 100644
--- a/ChangeLog.pre-2-6
+++ b/ChangeLog.pre-2-6
@@ -1,3 +1,9 @@
+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.
diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8
index 7890b77b3..7e3b1bd76 100644
--- a/ChangeLog.pre-2-8
+++ b/ChangeLog.pre-2-8
@@ -1,3 +1,9 @@
+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.
diff --git a/glib/gutils.c b/glib/gutils.c
index 92ad21612..f9fb93127 100644
--- a/glib/gutils.c
+++ b/glib/gutils.c
@@ -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.
*/