summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Withnall <pwithnall@endlessos.org>2022-10-24 12:38:15 +0100
committerPhilip Withnall <pwithnall@endlessos.org>2022-10-24 12:38:15 +0100
commit5553a44b1b9f4e7ed6afcb66c9fab4a3c0f3b58e (patch)
treeb14769d2fa087351d796bcc3e86a68efabf36a3c
parentf8c80391ae2b47e7bc83bdd582cbd44b131f61a0 (diff)
downloadglib-5553a44b1b9f4e7ed6afcb66c9fab4a3c0f3b58e.tar.gz
gfileutils: Mention possibility of relative paths in g_file_read_link()
It’s entirely possible that `g_file_read_link()` will return a relative path. Mention that in the documentation, and include a short example of how to make the path absolute for further computation. Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
-rw-r--r--glib/gfileutils.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/glib/gfileutils.c b/glib/gfileutils.c
index 4ee16e894..f0c8f6776 100644
--- a/glib/gfileutils.c
+++ b/glib/gfileutils.c
@@ -2256,9 +2256,28 @@ g_build_filename (const gchar *first_element,
* @error: return location for a #GError
*
* Reads the contents of the symbolic link @filename like the POSIX
- * readlink() function. The returned string is in the encoding used
+ * readlink() function.
+ *
+ * The returned string is in the encoding used
* for filenames. Use g_filename_to_utf8() to convert it to UTF-8.
*
+ * The returned string may also be a relative path. Use g_build_filename() to
+ * convert it to an absolute path:
+ * |[
+ * g_autoptr(GError) local_error = NULL;
+ * g_autofree gchar *link_target = g_file_read_link ("/etc/localtime", &local_error);
+ *
+ * if (local_error != NULL)
+ * g_error ("Error reading link: %s", local_error->message);
+ *
+ * if (!g_path_is_absolute (link_target))
+ * {
+ * g_autofree gchar *absolute_link_target = g_build_filename ("/etc", link_target, NULL);
+ * g_free (link_target);
+ * link_target = g_steal_pointer (&absolute_link_target);
+ * }
+ * ]|
+ *
* Returns: (type filename) (transfer full): A newly-allocated string with
* the contents of the symbolic link, or %NULL if an error occurred.
*