gnu: kio: Search 'smbd' on $PATH.
[jackhill/guix/guix.git] / gnu / packages / patches / libxt-guix-search-paths.patch
1 --- libXt-1.1.5/src/Intrinsic.c 2015-05-01 07:36:20.000000000 +0200
2 +++ Intrinsic.c 2016-12-12 00:42:16.567388450 +0100
3 @@ -1303,21 +1303,101 @@
4 } else (void) strcpy(*rest, string);
5 }
6
7 -/*
8 - * default path used if environment variable XFILESEARCHPATH
9 - * is not defined. Also substitued for %D.
10 - * The exact value should be documented in the implementation
11 - * notes for any Xt implementation.
12 +
13 +
14 +/*
15 + Return the default search path for the function
16 + XtResolvePathname to use if XFILESEARCHPATH is
17 + not defined.
18 +
19 + It returns the combination the set of values which are the 6 "stems" below,
20 + prepended with "/run/current-system/profile", and $GUIX_PROFILE and
21 + "$HOME/.guix-profile"
22 +
23 + These values provide the default paths where Guix/GuixSD can expect
24 + to find resources for installed packages.
25 */
26 -static const char *implementation_default_path(void)
27 +static const char *guix_default_path(void)
28 {
29 -#if defined(WIN32)
30 - static char xfilesearchpath[] = "";
31 -
32 - return xfilesearchpath;
33 -#else
34 - return XFILESEARCHPATHDEFAULT;
35 -#endif
36 + static const char *search_path_default_stem[] = {
37 + "/lib/X11/%L/%T/%N%C%S",
38 + "/lib/X11/%l/%T/%N%C%S",
39 + "/lib/X11/%T/%N%C%S",
40 + "/lib/X11/%L/%T/%N%S",
41 + "/lib/X11/%l/%T/%N%S",
42 + "/lib/X11/%T/%N%S"
43 + };
44 +
45 +#define SIZEOF_STEMS (strlen (search_path_default_stem[0]) \
46 + + strlen (search_path_default_stem[1]) \
47 + + strlen (search_path_default_stem[2]) \
48 + + strlen (search_path_default_stem[3]) \
49 + + strlen (search_path_default_stem[4]) \
50 + + strlen (search_path_default_stem[5]))
51 +
52 +
53 + int i;
54 + const char *current_profile = "/run/current-system/profile";
55 + char *home = getenv ("HOME");
56 + char *guix_profile = getenv ("GUIX_PROFILE");
57 +
58 + size_t bytesAllocd = SIZEOF_STEMS + 1;
59 +
60 + /* This function is evaluated multiple times and the calling
61 + code assumes that it is idempotent. So we must not allow
62 + (say) a changed environment variable to cause it to return
63 + something different. */
64 + static char *path = NULL;
65 + if (path)
66 + return path;
67 +
68 + bytesAllocd += 6 * (1 + strlen (current_profile));
69 +
70 + if (guix_profile != NULL)
71 + {
72 + bytesAllocd += SIZEOF_STEMS;
73 + bytesAllocd += 6 * (1 + strlen (guix_profile));
74 + }
75 +
76 + if (home != NULL)
77 + {
78 + bytesAllocd += SIZEOF_STEMS;
79 + bytesAllocd += 6 * (1 + strlen(home) + strlen ("/.guix-profile"));
80 + }
81 +
82 + path = XtMalloc(bytesAllocd);
83 + if (path == NULL) _XtAllocError(NULL);
84 +
85 + memset (path, 0, bytesAllocd);
86 +
87 + for (i = 0 ; i < 6 ; ++i)
88 + {
89 + strcat (path, current_profile);
90 + strcat (path, search_path_default_stem[i]);
91 + strcat (path, ":");
92 + }
93 +
94 + if (guix_profile != NULL)
95 + for (i = 0 ; i < 6 ; ++i)
96 + {
97 + strcat (path, guix_profile);
98 + strcat (path, search_path_default_stem[i]);
99 + strcat (path, ":");
100 + }
101 +
102 + if (home != NULL)
103 + for (i = 0 ; i < 6 ; ++i)
104 + {
105 + strcat (path, home);
106 + strcat (path, "/.guix-profile");
107 + strcat (path, search_path_default_stem[i]);
108 + strcat (path, ":");
109 + }
110 +
111 + /* Remove final : */
112 + path[strlen(path) - 1] = '\0';
113 +
114 + return path;
115 }
116
117
118 @@ -1345,7 +1425,7 @@
119 {
120 XtPerDisplay pd;
121 static const char *defaultPath = NULL;
122 - const char *impl_default = implementation_default_path();
123 + const char *impl_default = guix_default_path();
124 int idef_len = strlen(impl_default);
125 char *massagedPath;
126 int bytesAllocd, bytesLeft;