aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libfonts.h39
-rw-r--r--libfonts_get_default_font.c34
-rw-r--r--libfonts_get_default_rendering_settings.c22
-rw-r--r--libfonts_get_output_rendering_settings.c21
4 files changed, 66 insertions, 50 deletions
diff --git a/libfonts.h b/libfonts.h
index d4f948e..bdf9163 100644
--- a/libfonts.h
+++ b/libfonts.h
@@ -7,6 +7,12 @@
/**
+ * The header file's version of `struct libfonts_context`
+ */
+#define LIBFONTS_CONTEXT_VERSION 0
+
+
+/**
* Style-based default fonts
*/
enum libfonts_default_font {
@@ -1573,10 +1579,24 @@ struct libfonts_font_description {
/**
* Structure that can be used to spoof the
- * environment the library is executed in
+ * environment the library is executed in,
+ * as well as the print warnings from the
+ * library
*/
struct libfonts_context {
/**
+ * Set to `LIBFONTS_CONTEXT_VERSION`
+ */
+ int version;
+
+ /**
+ * Non-zero to remove all environment
+ * variables that are not included in
+ * `.environ`
+ */
+ int ignore_process_environ;
+
+ /**
* Environment variables to add or override
*
* `libfonts_used_environs` can be used to
@@ -1586,23 +1606,16 @@ struct libfonts_context {
char **environ;
/**
+ * Whether `.uid` is used
+ */
+ int use_context_uid;
+
+ /**
* The real user ID of the process
*
* Only used if `.use_context_uid` is non-zero
*/
uid_t uid;
-
- /**
- * Non-zero to remove all environment
- * variables that are not included in
- * `.environ`
- */
- int ignore_process_environ;
-
- /**
- * Whether `.uid` is used
- */
- int use_context_uid;
};
diff --git a/libfonts_get_default_font.c b/libfonts_get_default_font.c
index 25b18e1..5661e5c 100644
--- a/libfonts_get_default_font.c
+++ b/libfonts_get_default_font.c
@@ -4,13 +4,13 @@
static char *
-find(const char *dir_part1, const char *dir_part2, const char *dir_part3)
+find(const char *dir_part1, const char *dir_part2, const char *dir_part3, struct libfonts_context *ctx)
{
return NULL; /* TODO */
}
static char *
-getn(const char *file_part1, size_t file_part1_len, const char *file_part2, const char *name)
+getn(const char *file_part1, size_t file_part1_len, const char *file_part2, const char *name, struct libfonts_context *ctx)
{
size_t file_part2_len = strlen(file_part2);
char *path;
@@ -39,9 +39,9 @@ getn(const char *file_part1, size_t file_part1_len, const char *file_part2, cons
}
static char *
-get(const char *file_part1, const char *file_part2, const char *name)
+get(const char *file_part1, const char *file_part2, const char *name, struct libfonts_context *ctx)
{
- return getn(file_part1, strlen(file_part1), file_part2, name);
+ return getn(file_part1, strlen(file_part1), file_part2, name, ctx);
}
char *
@@ -72,51 +72,51 @@ libfonts_get_default_font(enum libfonts_default_font font, struct libfonts_conte
confenv = libfonts_getenv__("XDG_CONFIG_HOME", ctx);
if (confenv && *confenv) {
- ret = get(confenv, "/libfonts/default-fonts.conf", var);
+ ret = get(confenv, "/libfonts/default-fonts.conf", var, ctx);
if (ret)
goto out;
}
homeenv = libfonts_getenv__("HOME", ctx);
if (homeenv && *homeenv) {
- ret = get(homeenv, "/.config/libfonts/default-fonts.conf", var);
+ ret = get(homeenv, "/.config/libfonts/default-fonts.conf", var, ctx);
if (ret)
goto out;
- ret = get(homeenv, "/.libfonts/default-fonts.conf", var);
+ ret = get(homeenv, "/.libfonts/default-fonts.conf", var, ctx);
if (ret)
goto out;
}
home = libfonts_gethome__(ctx);
if (home && *home) {
- ret = get(home, "/.config/libfonts/default-fonts.conf", var);
+ ret = get(home, "/.config/libfonts/default-fonts.conf", var, ctx);
if (ret)
goto out;
- ret = get(home, "/.libfonts/default-fonts.conf", var);
+ ret = get(home, "/.libfonts/default-fonts.conf", var, ctx);
if (ret)
goto out;
}
if (confenv && *confenv) {
- ret = find(env, "/libfonts/", var);
+ ret = find(env, "/libfonts/", var, ctx);
if (ret)
goto out;
}
if (homeenv && *homeenv) {
- ret = find(homeenv, "/.config/libfonts/", var);
+ ret = find(homeenv, "/.config/libfonts/", var, ctx);
if (ret)
goto out;
- ret = find(homeenv, "/.libfonts/", var);
+ ret = find(homeenv, "/.libfonts/", var, ctx);
if (ret)
goto out;
}
if (home && *home) {
- ret = find(home, "/.config/libfonts/", var);
+ ret = find(home, "/.config/libfonts/", var, ctx);
if (ret)
goto out;
- ret = find(home, "/.libfonts/", var);
+ ret = find(home, "/.libfonts/", var, ctx);
if (ret)
goto out;
}
@@ -127,7 +127,7 @@ libfonts_get_default_font(enum libfonts_default_font font, struct libfonts_conte
next = strchr(&env[1], ':');
len = next ? (size_t)(next - env) : strlen(env);
if (len) {
- ret = getn(env, len, "/libfonts/default-fonts.conf", var);
+ ret = getn(env, len, "/libfonts/default-fonts.conf", var, ctx);
if (ret)
goto out;
}
@@ -135,11 +135,11 @@ libfonts_get_default_font(enum libfonts_default_font font, struct libfonts_conte
} while (next);
}
- ret = get("/etc", "/libfonts/default-fonts.conf", var);
+ ret = get("/etc", "/libfonts/default-fonts.conf", var, ctx);
if (ret)
goto out;
- ret = find("/etc", "/libfonts/", var);
+ ret = find("/etc", "/libfonts/", var, ctx);
if (ret)
goto out;
diff --git a/libfonts_get_default_rendering_settings.c b/libfonts_get_default_rendering_settings.c
index 0319897..fa1aa46 100644
--- a/libfonts_get_default_rendering_settings.c
+++ b/libfonts_get_default_rendering_settings.c
@@ -4,7 +4,8 @@
static int
-getn(const char *file_part1, size_t file_part1_len, const char *file_part2, struct libfonts_rendering_settings *settings)
+getn(const char *file_part1, size_t file_part1_len, const char *file_part2,
+ struct libfonts_rendering_settings *settings, struct libfonts_context *ctx)
{
size_t file_part2_len = strlen(file_part2);
char *path;
@@ -29,9 +30,10 @@ getn(const char *file_part1, size_t file_part1_len, const char *file_part2, stru
}
static int
-get(const char *file_part1, const char *file_part2, struct libfonts_rendering_settings *settings)
+get(const char *file_part1, const char *file_part2,
+ struct libfonts_rendering_settings *settings, struct libfonts_context *ctx)
{
- return getn(file_part1, strlen(file_part1), file_part2, settings);
+ return getn(file_part1, strlen(file_part1), file_part2, settings, ctx);
}
int
@@ -52,22 +54,22 @@ libfonts_get_default_rendering_settings(struct libfonts_rendering_settings *sett
env = libfonts_getenv__("XDG_CONFIG_HOME", ctx);
if (env && *env)
- if (get(env, "/libfonts/default-rendering.conf", settings))
+ if (get(env, "/libfonts/default-rendering.conf", settings, ctx))
goto out;
env = libfonts_getenv__("HOME", ctx);
if (env && *env) {
- if (get(env, "/.config/libfonts/default-rendering.conf", settings))
+ if (get(env, "/.config/libfonts/default-rendering.conf", settings, ctx))
goto out;
- if (get(env, "/.libfonts/default-rendering.conf", settings))
+ if (get(env, "/.libfonts/default-rendering.conf", settings, ctx))
goto out;
}
home = libfonts_gethome__(ctx);
if (home && *home) {
- if (get(home, "/.config/libfonts/default-rendering.conf", settings))
+ if (get(home, "/.config/libfonts/default-rendering.conf", settings, ctx))
goto out;
- if (get(home, "/.libfonts/default-rendering.conf", settings))
+ if (get(home, "/.libfonts/default-rendering.conf", settings, ctx))
goto out;
}
@@ -77,13 +79,13 @@ libfonts_get_default_rendering_settings(struct libfonts_rendering_settings *sett
next = strchr(&env[1], ':');
len = next ? (size_t)(next - env) : strlen(env);
if (len)
- if (getn(env, len, "/libfonts/default-rendering.conf", settings))
+ if (getn(env, len, "/libfonts/default-rendering.conf", settings, ctx))
goto out;
env += len + 1;
} while (next);
}
- if (get("/etc", "/libfonts/default-rendering.conf", settings))
+ if (get("/etc", "/libfonts/default-rendering.conf", settings, ctx))
goto out;
ret = 0;
diff --git a/libfonts_get_output_rendering_settings.c b/libfonts_get_output_rendering_settings.c
index 7554d51..aa3af95 100644
--- a/libfonts_get_output_rendering_settings.c
+++ b/libfonts_get_output_rendering_settings.c
@@ -5,7 +5,7 @@
static int
getn(const char *file_part1, size_t file_part1_len, const char *file_part2,
- struct libfonts_rendering_settings *settings, const char *name)
+ struct libfonts_rendering_settings *settings, const char *name, struct libfonts_context *ctx)
{
size_t file_part2_len = strlen(file_part2);
char *path;
@@ -32,9 +32,10 @@ getn(const char *file_part1, size_t file_part1_len, const char *file_part2,
}
static int
-get(const char *file_part1, const char *file_part2, struct libfonts_rendering_settings *settings, const char *name)
+get(const char *file_part1, const char *file_part2, struct libfonts_rendering_settings *settings,
+ const char *name, struct libfonts_context *ctx)
{
- return getn(file_part1, strlen(file_part1), file_part2, settings, name);
+ return getn(file_part1, strlen(file_part1), file_part2, settings, name, ctx);
}
int
@@ -60,22 +61,22 @@ libfonts_get_output_rendering_settings(struct libfonts_rendering_settings *setti
env = libfonts_getenv__("XDG_CONFIG_HOME", ctx);
if (env && *env)
- if (get(env, "/libfonts/output-rendering.conf", settings, name))
+ if (get(env, "/libfonts/output-rendering.conf", settings, name, ctx))
goto out;
env = libfonts_getenv__("HOME", ctx);
if (env && *env) {
- if (get(env, "/.config/libfonts/output-rendering.conf", settings, name))
+ if (get(env, "/.config/libfonts/output-rendering.conf", settings, name, ctx))
goto out;
- if (get(env, "/.libfonts/output-rendering.conf", settings, name))
+ if (get(env, "/.libfonts/output-rendering.conf", settings, name, ctx))
goto out;
}
home = libfonts_gethome__(ctx);
if (home && *home) {
- if (get(home, "/.config/libfonts/output-rendering.conf", settings, name))
+ if (get(home, "/.config/libfonts/output-rendering.conf", settings, name, ctx))
goto out;
- if (get(home, "/.libfonts/output-rendering.conf", settings, name))
+ if (get(home, "/.libfonts/output-rendering.conf", settings, name, ctx))
goto out;
}
@@ -85,13 +86,13 @@ libfonts_get_output_rendering_settings(struct libfonts_rendering_settings *setti
next = strchr(&env[1], ':');
len = next ? (size_t)(next - env) : strlen(env);
if (len)
- if (getn(env, len, "/libfonts/output-rendering.conf", settings, name))
+ if (getn(env, len, "/libfonts/output-rendering.conf", settings, name, ctx))
goto out;
env += len + 1;
} while (next);
}
- if (get("/etc", "/libfonts/output-rendering.conf", settings, name))
+ if (get("/etc", "/libfonts/output-rendering.conf", settings, name, ctx))
goto out;
ret = 0;