[libgsystem] fileutils: Add gs_file_realpath as well



commit 4230291c74041883559057f73a910a28965da194
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Wed Jun 19 22:19:32 2013 -0400

    fileutils: Add gs_file_realpath as well

 gsystem-file-utils.c |   23 +++++++++++++++++++++++
 gsystem-file-utils.h |    2 ++
 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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]