diff options
author | Mattias Andrée <maandree@kth.se> | 2023-01-18 22:01:38 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2023-01-18 22:01:38 +0100 |
commit | f00bb715c248c3e4a8ca573d1cb6d146167d7643 (patch) | |
tree | 82237a0ac9988142870384c70e2e493d09519af1 | |
parent | m (diff) | |
download | libfonts-f00bb715c248c3e4a8ca573d1cb6d146167d7643.tar.gz libfonts-f00bb715c248c3e4a8ca573d1cb6d146167d7643.tar.bz2 libfonts-f00bb715c248c3e4a8ca573d1cb6d146167d7643.tar.xz |
Fix libfonts_get_font_root_dirs and add libfonts dir
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | libfonts_get_font_root_dirs.c | 49 |
1 files changed, 39 insertions, 10 deletions
diff --git a/libfonts_get_font_root_dirs.c b/libfonts_get_font_root_dirs.c index 1ebbb96..053fb7c 100644 --- a/libfonts_get_font_root_dirs.c +++ b/libfonts_get_font_root_dirs.c @@ -66,39 +66,68 @@ libfonts_get_font_root_dirs(char ***dirsp, size_t *countp, struct libfonts_conte const char *env; char **new, *home = NULL; size_t size = 0; + const char *env_xdg_data_home = libfonts_getenv__("XDG_DATA_HOME", ctx); + const char *env_home = libfonts_getenv__("HOME", ctx); + const char *env_xdg_data_dirs = libfonts_getenv__("XDG_DATA_DIRS", ctx); *dirsp = NULL; *countp = 0; + env = libfonts_getenv__("LIBFONTS_FONT_DIRS", ctx); - if (env && *env && add_dirs(dirsp, countp, &size, env, "/fonts")) + if (env && *env && add_dirs(dirsp, countp, &size, env, "")) + goto fail; + + + env = env_xdg_data_home; + if (env && *env && add_dir(dirsp, countp, &size, env, "/libfonts")) + goto fail; + + env = env_home; + if (env && *env && (add_dir(dirsp, countp, &size, env, "/.local/share/libfonts") || + add_dir(dirsp, countp, &size, env, "/.libfonts"))) + goto fail; + + home = libfonts_gethome__(ctx); + if (home && *home && (add_dir(dirsp, countp, &size, home, "/.local/share/libfonts") || + add_dir(dirsp, countp, &size, home, "/.libfonts"))) goto fail; - env = libfonts_getenv__("XDG_DATA_HOME", ctx); + + env = env_xdg_data_dirs; + if (env && *env && add_dirs(dirsp, countp, &size, env, "/libfonts")) + goto fail; + + if (add_dirs(dirsp, countp, &size, "/usr/local/share", "/libfonts") || + add_dirs(dirsp, countp, &size, "/usr/share", "/libfonts")) + goto fail; + + + env = env_xdg_data_home; if (env && *env && add_dir(dirsp, countp, &size, env, "/fonts")) goto fail; - env = libfonts_getenv__("HOME", ctx); + env = env_home; if (env && *env && (add_dir(dirsp, countp, &size, env, "/.local/share/fonts") || add_dir(dirsp, countp, &size, env, "/.fonts"))) goto fail; - home = libfonts_gethome__(ctx); - if (home && *home && (add_dir(dirsp, countp, &size, env, "/.local/share/fonts") || - add_dir(dirsp, countp, &size, env, "/.fonts"))) + if (home && *home && (add_dir(dirsp, countp, &size, home, "/.local/share/fonts") || + add_dir(dirsp, countp, &size, home, "/.fonts"))) goto fail; free(home); home = NULL; - env = libfonts_getenv__("XDG_DATA_DIRS", ctx); + + env = env_xdg_data_dirs; if (env && *env && add_dirs(dirsp, countp, &size, env, "/fonts")) goto fail; - if (add_dirs(dirsp, countp, &size, "/usr/local/share", "/fonts")) - goto fail; - if (add_dirs(dirsp, countp, &size, "/usr/share", "/fonts")) + if (add_dirs(dirsp, countp, &size, "/usr/local/share", "/fonts") || + add_dirs(dirsp, countp, &size, "/usr/share", "/fonts")) goto fail; + if (*countp == size) { if (SIZE_MAX / sizeof(**dirsp) - 1) goto enomem; |