summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gsystem-file-utils.c23
-rw-r--r--gsystem-file-utils.h2
2 files changed, 25 insertions, 0 deletions
diff --git a/gsystem-file-utils.c b/gsystem-file-utils.c
index 5fb0252..bc34b7c 100644
--- a/gsystem-file-utils.c
+++ b/gsystem-file-utils.c
@@ -33,6 +33,7 @@
#include <glib/gstdio.h>
#include <gio/gunixinputstream.h>
#include <glib-unix.h>
+#include <limits.h>
static int
close_nointr (int fd)
@@ -967,3 +968,25 @@ gs_file_get_relpath (GFile *one,
return g_string_free (path, FALSE);
}
+
+/**
+ * gs_file_realpath:
+ * @file: A #GFile
+ *
+ * Return a #GFile that contains the same path with symlinks
+ * followed. That is, it's a #GFile whose path is the result
+ * of calling realpath() on @file.
+ *
+ * Returns: (transfer full): A new #GFile
+ */
+GFile *
+gs_file_realpath (GFile *file)
+{
+ gchar *path;
+ gchar path_real[PATH_MAX];
+
+ path = g_file_get_path (file);
+ realpath ((const char *) path, path_real);
+ g_free (path);
+ return g_file_new_for_path (path_real);
+}
diff --git a/gsystem-file-utils.h b/gsystem-file-utils.h
index 9eb8576..3fa01b6 100644
--- a/gsystem-file-utils.h
+++ b/gsystem-file-utils.h
@@ -101,6 +101,8 @@ gchar *gs_file_load_contents_utf8 (GFile *file,
gchar *gs_file_get_relpath (GFile *one,
GFile *two);
+GFile * gs_file_realpath (GFile *file);
+
G_END_DECLS
#endif