[libgsystem] fileutils: Handles return value of realpath in case of errors



commit ddcaa639e4fa1103cc43318882b447b98890e370
Author: Alberto Ruiz <aruiz gnome org>
Date:   Wed Jul 17 23:53:10 2013 +0200

    fileutils: Handles return value of realpath in case of errors
    
    Signed-off-by: Alberto Ruiz <aruiz gnome org>

 gsystem-file-utils.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
---
diff --git a/gsystem-file-utils.c b/gsystem-file-utils.c
index 69a2caf..cc7fa98 100644
--- a/gsystem-file-utils.c
+++ b/gsystem-file-utils.c
@@ -1025,7 +1025,7 @@ gs_file_get_relpath (GFile *one,
  * followed. That is, it's a #GFile whose path is the result
  * of calling realpath() on @file.
  *
- * Returns: (transfer full): A new #GFile
+ * Returns: (allow-none) (transfer full): A new #GFile or %NULL if @file is invalid
  */
 GFile *
 gs_file_realpath (GFile *file)
@@ -1034,7 +1034,13 @@ gs_file_realpath (GFile *file)
   gchar path_real[PATH_MAX];
 
   path = g_file_get_path (file);
-  realpath ((const char *) path, path_real);
+
+  if (realpath ((const char *) path, path_real) == NULL)
+    {
+      g_free (path);
+      return NULL;
+    }
+
   g_free (path);
   return g_file_new_for_path (path_real);
 }


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