projects/guix·blob python-team · refs

78 lines · 3.2 KiB

1Upstream status: This patch was taken from leptonica upstream.
2
3Backported to ghostscripts bundled leptonica.
4
5From f04da7c816feb1d5f689c34f3d0e7e3621edf1f5 Mon Sep 17 00:00:00 2001
6From: Samuel Thibault <[email protected]>
7Date: Wed, 1 Feb 2023 19:35:43 +0100
8Subject: [PATCH] Fix GNU/Hurd build
9
10There is no PATH_MAX limitation on GNU/Hurd, and realpath() can be
11safely be used with its second parameter set to NULL (as required by
12posix since its version 2001).
13---
14 src/sarray1.c | 29 +++++++++++++++++++++++------
15 1 file changed, 23 insertions(+), 6 deletions(-)
16
17--- a/src/sarray1.c 2023-06-13 12:31:13.393672916 +0200
18+++ a/src/sarray1.c 2023-06-13 12:34:13.574237149 +0200
19@@ -1953,7 +1953,11 @@
20 SARRAY *
21 getFilenamesInDirectory(const char *dirname)
22 {
23+#if _POSIX_VERSION >= 200112 || defined(__GLIBC__)
24+char *dir;
25+#else
26 char dir[PATH_MAX + 1];
27+#endif
28 char *realdir, *stat_path, *ignore;
29 size_t size;
30 SARRAY *safiles;
31@@ -1976,17 +1980,28 @@
32 * If the file or directory exists, realpath returns its path;
33 else it returns NULL.
34 * If the second arg to realpath is passed in, the canonical path
35- is returned there. Use a buffer of sufficient size. If the
36- second arg is NULL, the path is malloc'd and returned if the
37- file or directory exists.
38- We pass in a buffer for the second arg, and check that the canonical
39- directory path was made. The existence of the directory is checked
40- later, after its actual path is returned by genPathname(). */
41+ is returned there. Use a buffer of sufficient size.
42+ We pass in a buffer for the second arg, and check that the
43+ canonical directory path was made. The existence of the
44+ directory is checked later, after its actual path is returned by
45+ genPathname().
46+ With GNU libc or Posix 2001, if the second arg is NULL, the path
47+ is malloc'd and returned if the file or directory exists.
48+ */
49+#if _POSIX_VERSION >= 200112 || defined(__GLIBC__)
50+ dir = realpath(dirname, NULL);
51+ if (dir == NULL)
52+ return (SARRAY *)ERROR_PTR("dir not made", __func__, NULL);
53+#else
54 dir[0] = '\0'; /* init empty in case realpath() fails to write it */
55 ignore = realpath(dirname, dir);
56 if (dir[0] == '\0')
57 return (SARRAY *)ERROR_PTR("dir not made", procName, NULL);
58+#endif
59 realdir = genPathname(dir, NULL);
60+#if _POSIX_VERSION >= 200112 || defined(__GLIBC__)
61+ LEPT_FREE(dir);
62+#endif
63 if ((pdir = opendir(realdir)) == NULL) {
64 LEPT_FREE(realdir);
65 return (SARRAY *)ERROR_PTR("pdir not opened", procName, NULL);
66@@ -1998,10 +2013,12 @@
67 stat_ret = fstatat(dfd, pdirentry->d_name, &st, 0);
68 #else
69 size = strlen(realdir) + strlen(pdirentry->d_name) + 2;
70+#if _POSIX_VERSION < 200112 && !defined(__GLIBC__)
71 if (size > PATH_MAX) {
72 L_ERROR("size = %zu too large; skipping\n", procName, size);
73 continue;
74 }
75+#endif
76 stat_path = (char *)LEPT_CALLOC(size, 1);
77 snprintf(stat_path, size, "%s/%s", realdir, pdirentry->d_name);
78 stat_ret = stat(stat_path, &st);