1 diff --git a/src/Intrinsic.c b/src/Intrinsic.c
2 index c9624ec..addcdba 100644
5 @@ -1312,21 +1312,101 @@ static void FillInLangSubs(
6 } else (void) strcpy(*rest, string);
12 - * default path used if environment variable XFILESEARCHPATH
13 - * is not defined. Also substitued for %D.
14 - * The exact value should be documented in the implementation
15 - * notes for any Xt implementation.
16 + Return the default search path for the function
17 + XtResolvePathname to use if XFILESEARCHPATH is
20 + It returns the combination the set of values which are the 6 "stems" below,
21 + prepended with "/run/current-system/profile", and $GUIX_PROFILE and
22 + "$HOME/.guix-profile"
24 + These values provide the default paths where Guix/GuixSD can expect
25 + to find resources for installed packages.
27 -static const char *implementation_default_path(void)
28 +static const char *guix_default_path(void)
31 - static char xfilesearchpath[] = "";
32 + static const char *search_path_default_stem[] = {
33 + "/lib/X11/%L/%T/%N%C%S",
34 + "/lib/X11/%l/%T/%N%C%S",
35 + "/lib/X11/%T/%N%C%S",
36 + "/lib/X11/%L/%T/%N%S",
37 + "/lib/X11/%l/%T/%N%S",
41 +#define SIZEOF_STEMS (strlen (search_path_default_stem[0]) \
42 + + strlen (search_path_default_stem[1]) \
43 + + strlen (search_path_default_stem[2]) \
44 + + strlen (search_path_default_stem[3]) \
45 + + strlen (search_path_default_stem[4]) \
46 + + strlen (search_path_default_stem[5]))
50 + const char *current_profile = "/run/current-system/profile";
51 + char *home = getenv ("HOME");
52 + char *guix_profile = getenv ("GUIX_PROFILE");
54 + size_t bytesAllocd = SIZEOF_STEMS + 1;
56 + /* This function is evaluated multiple times and the calling
57 + code assumes that it is idempotent. So we must not allow
58 + (say) a changed environment variable to cause it to return
59 + something different. */
60 + static char *path = NULL;
64 + bytesAllocd += 6 * (1 + strlen (current_profile));
66 + if (guix_profile != NULL)
68 + bytesAllocd += SIZEOF_STEMS;
69 + bytesAllocd += 6 * (1 + strlen (guix_profile));
72 - return xfilesearchpath;
74 - return XFILESEARCHPATHDEFAULT;
78 + bytesAllocd += SIZEOF_STEMS;
79 + bytesAllocd += 6 * (1 + strlen(home) + strlen ("/.guix-profile"));
82 + path = XtMalloc(bytesAllocd);
83 + if (path == NULL) _XtAllocError(NULL);
85 + memset (path, 0, bytesAllocd);
87 + for (i = 0 ; i < 6 ; ++i)
89 + strcat (path, current_profile);
90 + strcat (path, search_path_default_stem[i]);
94 + if (guix_profile != NULL)
95 + for (i = 0 ; i < 6 ; ++i)
97 + strcat (path, guix_profile);
98 + strcat (path, search_path_default_stem[i]);
103 + for (i = 0 ; i < 6 ; ++i)
105 + strcat (path, home);
106 + strcat (path, "/.guix-profile");
107 + strcat (path, search_path_default_stem[i]);
108 + strcat (path, ":");
111 + /* Remove final : */
112 + path[strlen(path) - 1] = '\0';
118 @@ -1354,7 +1434,7 @@ _XtString XtResolvePathname(
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 = (int) strlen(impl_default);
126 int bytesAllocd, bytesLeft;