From 4230291c74041883559057f73a910a28965da194 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Wed, 19 Jun 2013 22:19:32 -0400 Subject: fileutils: Add gs_file_realpath as well --- gsystem-file-utils.c | 23 +++++++++++++++++++++++ gsystem-file-utils.h | 2 ++ 2 files changed, 25 insertions(+) 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 #include #include +#include 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 -- cgit v1.2.1