projects/guix·blob python-team · refs

122 lines · 3.4 KiB

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