Fix #618: Avoid using PATH_MAX where not available
authorAndreas Rönnquist <>
Mon, 25 Jun 2018 09:19:46 +0000 (10:19 +0100)
committerColin Clark <colin.clark@cclark.uk>
Mon, 25 Jun 2018 09:19:46 +0000 (10:19 +0100)
https://github.com/BestImageViewer/geeqie/pull/618

Geeqie fails to build on Hurd because of not finding PATH_MAX, this fix would avoid using PATH_MAX on systems where it isn't available.

src/ui_fileops.c

index ea8c7c1..822792d 100644 (file)
@@ -570,10 +570,20 @@ gboolean copy_file(const gchar *s, const gchar *t)
                        {
                        gchar *absolute;
 
-                       absolute = g_malloc(PATH_MAX + 1);
                        char *lastslash = strrchr(sl, G_DIR_SEPARATOR);
                        int len = lastslash - sl + 1;
 
+                       int path_max;
+#ifdef PATH_MAX
+                       path_max = PATH_MAX;
+#else
+                       path_max = pathconf(sl, _PC_PATH_MAX);
+                       if (path_max <= 0)
+                               path_max = 4096;
+#endif
+
+                       absolute = g_malloc(path_max + 1);
+
                        strncpy(absolute, sl, len);
                        strcpy(absolute + len, link_target);
                        strcpy(link_target, absolute);