summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasper St. Pierre <jstpierre@mecheye.net>2013-06-19 22:19:32 -0400
committerJasper St. Pierre <jstpierre@mecheye.net>2013-06-19 22:23:05 -0400
commit4230291c74041883559057f73a910a28965da194 (patch)
tree03844618ca99bb224e82304a41fb44ae94cec4d3
parent826282db8c23fc1c4bba1985c643a626ff1f0c2c (diff)
downloadlibgsystem-4230291c74041883559057f73a910a28965da194.tar.gz
fileutils: Add gs_file_realpath as well
-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