summaryrefslogtreecommitdiff
path: root/xkb
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2021-03-18 09:44:53 +1000
committerPovilas Kanapickas <povilas@radix.lt>2021-04-09 17:37:29 +0000
commitf6b8f8c071a575e54645aeb0bd3cb37377b0e4d3 (patch)
treed619c2b7f4a38728ecd482e98a5ddec1f063dba2 /xkb
parenteceafd4a2d159f5c2b789ad77ee283c2aa848a59 (diff)
xkb: don't require a trailing slash for the XKM output dir
Rework the function to use a single snprintf call instead of a mix of strcpy/strcats. This now also appends a trailing slash where needed so we don't rely on the build system to set this for us. Also, since /tmp/ is the fallback and we never check if everything succeeded, assert if we can't use /tmp/. This will never be triggered anyway, the only caller to OutputDirectory() uses sizeof(PATH_MAX-sized array). Follow-up from 6c51818a0f55282cbe5a870f58ca82ca45ee472d Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'xkb')
-rw-r--r--xkb/ddxLoad.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/xkb/ddxLoad.c b/xkb/ddxLoad.c
index ea7e34700..f9b7b06d9 100644
--- a/xkb/ddxLoad.c
+++ b/xkb/ddxLoad.c
@@ -62,22 +62,27 @@ LoadXKM(unsigned want, unsigned need, const char *keymap, XkbDescPtr *xkbRtrn);
static void
OutputDirectory(char *outdir, size_t size)
{
+ const char *directory = NULL;
+ const char *pathsep = "";
+ int r = -1;
+
#ifndef WIN32
/* Can we write an xkm and then open it too? */
- if (access(XKM_OUTPUT_DIR, W_OK | X_OK) == 0 &&
- (strlen(XKM_OUTPUT_DIR) < size)) {
- (void) strcpy(outdir, XKM_OUTPUT_DIR);
+ if (access(XKM_OUTPUT_DIR, W_OK | X_OK) == 0) {
+ directory = XKM_OUTPUT_DIR;
+ if (XKM_OUTPUT_DIR[strlen(XKM_OUTPUT_DIR) - 1] != '/')
+ pathsep = "/";
}
- else
#else
- if (strlen(Win32TempDir()) + 1 < size) {
- (void) strcpy(outdir, Win32TempDir());
- (void) strcat(outdir, "\\");
- }
- else
+ directory = Win32TempDir();
+ pathsep = "\\";
#endif
- if (strlen("/tmp/") < size) {
- (void) strcpy(outdir, "/tmp/");
+
+ if (directory)
+ r = snprintf(outdir, size, "%s%s", directory, pathsep);
+ if (r < 0 || r >= size) {
+ assert(strlen("/tmp/") < size);
+ strcpy(outdir, "/tmp/");
}
}