aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/file-utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/file-utils.c')
-rw-r--r--src/file-utils.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/file-utils.c b/src/file-utils.c
index 75bcb48..7c37b27 100644
--- a/src/file-utils.c
+++ b/src/file-utils.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2012-2025 Robin Haberkorn
+ * Copyright (C) 2012-2026 Robin Haberkorn
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -109,6 +109,14 @@ teco_file_set_attributes(const gchar *filename, teco_file_attributes_t attrs)
#ifdef G_OS_UNIX
+/*
+ * NOTE: This version does not resolve symlinks to non-existing paths.
+ * It could be improved by repeating readlink() and g_canonicalize_filename(),
+ * but it would require glib v2.58.0.
+ * Alternatively we could also iteratively resolve all path components.
+ * Currently, we simply do not rely on successful canonicalization of
+ * yet non-existing paths.
+ */
gchar *
teco_file_get_absolute_path(const gchar *path)
{
@@ -137,13 +145,12 @@ teco_file_is_visible(const gchar *path)
#if GLIB_CHECK_VERSION(2,58,0)
/*
- * FIXME: This should perhaps be preferred on any platform.
- * But it will complicate preprocessing.
+ * NOTE: Does not resolve symlinks.
*/
gchar *
teco_file_get_absolute_path(const gchar *path)
{
- return g_canonicalize_filename(path, NULL);
+ return path ? g_canonicalize_filename(path, NULL) : NULL;
}
#else /* !GLIB_CHECK_VERSION(2,58,0) */
@@ -353,7 +360,7 @@ teco_file_expand_path(const gchar *path)
*/
g_auto(teco_string_t) home = {NULL, 0};
if (!qreg->vtable->get_string(qreg, &home.data, &home.len, NULL, NULL) ||
- teco_string_contains(&home, '\0'))
+ teco_string_contains(home, '\0'))
return g_strdup(path);
g_assert(home.data != NULL);
@@ -419,7 +426,7 @@ teco_file_auto_complete(const gchar *filename, GFileTest file_test, teco_string_
while ((cur_basename.data = (gchar *)g_dir_read_name(dir))) {
cur_basename.len = strlen(cur_basename.data);
- if (string_diff(&cur_basename, basename, basename_len) != basename_len)
+ if (string_diff(cur_basename, basename, basename_len) != basename_len)
/* basename is not a prefix of cur_basename */
continue;
@@ -453,7 +460,7 @@ teco_file_auto_complete(const gchar *filename, GFileTest file_test, teco_string_
other_file.data = (gchar *)g_slist_next(files)->data + filename_len;
other_file.len = strlen(other_file.data);
- gsize len = string_diff(&other_file, cur_filename + filename_len,
+ gsize len = string_diff(other_file, cur_filename + filename_len,
strlen(cur_filename) - filename_len);
if (len < prefix_len)
prefix_len = len;