summaryrefslogtreecommitdiffstats
path: root/gettext-tools/src/search-path.c
diff options
context:
space:
mode:
authorDaiki Ueno <ueno@gnu.org>2016-05-20 17:34:25 +0900
committerDaiki Ueno <ueno@gnu.org>2016-05-20 17:34:25 +0900
commit44f7525b65f08ebd21635ae83b407557722e8795 (patch)
treea4790f7b078e9b0e27fed0d7b0d0539b9f72847f /gettext-tools/src/search-path.c
parenta83370b0514c68aeda8a21f0019a70a7b5b4338f (diff)
downloadexternal_gettext-44f7525b65f08ebd21635ae83b407557722e8795.zip
external_gettext-44f7525b65f08ebd21635ae83b407557722e8795.tar.gz
external_gettext-44f7525b65f08ebd21635ae83b407557722e8795.tar.bz2
search-path: Fix XDG_DATA_DIRS traversal
* gettext-tools/src/search-path.c (foreach_elements): Append "gettext" suffix to each element from XDG_DATA_DIRS.
Diffstat (limited to 'gettext-tools/src/search-path.c')
-rw-r--r--gettext-tools/src/search-path.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/gettext-tools/src/search-path.c b/gettext-tools/src/search-path.c
index c085ec0..14b417f 100644
--- a/gettext-tools/src/search-path.c
+++ b/gettext-tools/src/search-path.c
@@ -41,16 +41,16 @@ struct path_array_ty {
};
static void
-foreach_components (const char *dirs, foreach_function_ty function, void *data)
+foreach_elements (const char *dirs, foreach_function_ty function, void *data)
{
const char *start = dirs;
- /* Count the number of valid components in GETTEXTDATADIRS. */
+ /* Count the number of valid elements in GETTEXTDATADIRS. */
while (*start != '\0')
{
char *end = strchrnul (start, ':');
- /* Skip empty component. */
+ /* Skip empty element. */
if (start != end)
function (start, end - start, data);
@@ -87,7 +87,12 @@ fill (const char *dir, size_t len, void *data)
}
/* Find the standard search path for data files. Returns a NULL
- terminated list of strings. */
+ terminated list of strings. The order in the path is as follows:
+
+ 1. $GETTEXTDATADIR or GETTEXTDATADIR
+ 2. $GETTEXTDATADIRS
+ 3. $XDG_DATA_DIRS, where each element is suffixed with "gettext"
+ 4. $GETTEXTDATADIR or GETTEXTDATADIR, suffixed with PACKAGE_SUFFIX */
char **
get_search_path (const char *sub)
{
@@ -99,15 +104,14 @@ get_search_path (const char *sub)
gettextdatadirs = getenv ("GETTEXTDATADIRS");
if (gettextdatadirs != NULL)
- foreach_components (gettextdatadirs, increment, &count);
+ foreach_elements (gettextdatadirs, increment, &count);
gettextdatadirs = getenv ("XDG_DATA_DIRS");
if (gettextdatadirs != NULL)
- foreach_components (gettextdatadirs, increment, &count);
+ foreach_elements (gettextdatadirs, increment, &count);
array.ptr = XCALLOC (count + 1, char *);
array.len = 0;
- array.sub = sub;
gettextdatadir = getenv ("GETTEXTDATADIR");
if (gettextdatadir == NULL || gettextdatadir[0] == '\0')
@@ -116,19 +120,29 @@ get_search_path (const char *sub)
install". */
gettextdatadir = relocate (GETTEXTDATADIR);
+ /* Append element from GETTEXTDATADIR. */
if (sub == NULL)
name = xstrdup (gettextdatadir);
else
name = xconcatenated_filename (gettextdatadir, sub, NULL);
array.ptr[array.len++] = name;
+ /* Append elements from GETTEXTDATADIRS. */
+ array.sub = sub;
gettextdatadirs = getenv ("GETTEXTDATADIRS");
if (gettextdatadirs != NULL)
- foreach_components (gettextdatadirs, fill, &array);
+ foreach_elements (gettextdatadirs, fill, &array);
+ /* Append elements from XDG_DATA_DIRS. Note that each element needs
+ to have "gettext" suffix. */
+ if (sub == NULL)
+ array.sub = xstrdup ("gettext");
+ else
+ array.sub = xconcatenated_filename ("gettext", sub, NULL);
gettextdatadirs = getenv ("XDG_DATA_DIRS");
if (gettextdatadirs != NULL)
- foreach_components (gettextdatadirs, fill, &array);
+ foreach_elements (gettextdatadirs, fill, &array);
+ free (array.sub);
/* Append version specific directory. */
base = xasprintf ("%s%s", gettextdatadir, PACKAGE_SUFFIX);