@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 :-)