[anjuta] libanjuta: bgo #699330 - Implement anjuta_util_get_real_path in Windows
- From: Sebastien Granjoux <sgranjoux src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [anjuta] libanjuta: bgo #699330 - Implement anjuta_util_get_real_path in Windows
- Date: Mon, 6 May 2013 20:12:04 +0000 (UTC)
commit f39aeb3149327404c74b19b79413ac1d9c951732
Author: Arnel A. Borja <kyoushuu yahoo com>
Date: Sun Apr 7 00:17:27 2013 +0800
libanjuta: bgo #699330 - Implement anjuta_util_get_real_path in Windows
Use GetFullPathName to get the real path.
libanjuta/anjuta-utils.c | 41 ++++++++++++++++++++++++++++++++++++-----
1 files changed, 36 insertions(+), 5 deletions(-)
---
diff --git a/libanjuta/anjuta-utils.c b/libanjuta/anjuta-utils.c
index 64145f1..6506b7b 100644
--- a/libanjuta/anjuta-utils.c
+++ b/libanjuta/anjuta-utils.c
@@ -45,9 +45,6 @@
#include <unistd.h>
#include <stdio.h>
#include <string.h>
-#ifndef G_OS_WIN32
-#include <pwd.h>
-#endif
#include <gio/gio.h>
#include <glib/gi18n.h>
@@ -55,6 +52,13 @@
#include <glib/gstdio.h>
#include <gtk/gtk.h>
+#ifndef G_OS_WIN32
+#include <pwd.h>
+#else
+#define WIN32_MEAN_AND_LEAN
+#include <windows.h>
+#endif
+
#include <libanjuta/anjuta-utils.h>
#include <libanjuta/anjuta-debug.h>
#include <libanjuta/interfaces/ianjuta-editor-cell.h>
@@ -761,7 +765,8 @@ anjuta_util_get_real_path (const gchar *path)
if (path != NULL)
{
gchar *result;
-#ifdef PATH_MAX
+#ifndef G_OS_WIN32
+# ifdef PATH_MAX
gchar buf[PATH_MAX+1];
result = realpath (path, buf);
@@ -770,7 +775,7 @@ anjuta_util_get_real_path (const gchar *path)
*(buf + PATH_MAX) = '\0'; /* ensure a terminator */
return g_strdup (buf);
}
-#else
+# else
char *buf;
/* the string returned by realpath should be cleaned with
free(), not g_free() */
@@ -781,6 +786,32 @@ anjuta_util_get_real_path (const gchar *path)
free (buf);
return result;
}
+# endif
+#else
+ char dummy;
+ int rc, len;
+
+ /* Get length of path */
+ rc = GetFullPathName (path, 1, &dummy, NULL);
+ if (rc == 0)
+ {
+ /* Weird failure */
+ return g_strdup (path);
+ }
+
+ len = rc + 1;
+ result = g_malloc (len);
+
+ /* Get the real path */
+ rc = GetFullPathName (path, len, result, NULL);
+ if (rc == 0 || rc > len)
+ {
+ /* Another weird failure */
+ g_free (result);
+ return g_strdup (path);
+ }
+
+ return result;
#endif
}
return NULL;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]