[Github-comments] [geany/geany] Remove deprecated symbol: tm_get_real_path (PR #3024)

elextr notifications at xxxxx
Tue Nov 30 00:57:17 UTC 2021


@elextr commented on this pull request.



> @@ -2414,6 +2419,48 @@ void utils_start_new_geany_instance(const gchar *doc_path)
 }
 
 
+
+static int get_path_max(const char *path)
+{
+#ifdef PATH_MAX
+	return PATH_MAX;
+#else
+	int path_max = pathconf(path, _PC_PATH_MAX);
+	if (path_max <= 0)
+		path_max = 4096;
+	return path_max;
+#endif

On every modern Linux the pathconf value is "unsuitable for allocating memory", so that will fail too if PATH_MAX is not something sane, and IIUC on some systems its not defined.  So I would never use the get_path_max() value to allocate memory, its known to fail on modern systems, whereas realpath() should work on modern systems.  As the system realpath() can legitimately fail for other reasons, allocating memory if it fails is not a good idea.

I don't know if the Windows hack is needed still, lets assume so until some Windows guru says it went out with DOS :)

I would write it as (pseudocode):
```
#if windows and not have_realpath
    gchar *utils_get_real_path(const gchar *file_name){
       the windows implementation allocating PATH_MAX (IIUC it is always defined on Windows)
    }
#else
    gchar *utils_get_real_path(const gchar *file_name){
        return realpath(file_name, NULL);
    }
#endif
```   

We really should check errno after calling `realpath()` since there is a GNU extension that returns a partial path on EACCESS or ENOENT, but hell we almost never check it, why start now :-)


-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany/pull/3024#discussion_r758849375
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.geany.org/pipermail/github-comments/attachments/20211129/ca1d9c28/attachment-0001.htm>


More information about the Github-comments mailing list