diff --git a/src/config.cpp b/src/config.cpp index 92eef85..cac8592 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -24,6 +24,7 @@ #include "string.h" #include "unicode.h" #include +#include #define MAX_FILE_SZ 65536 #define MAX_LINE_LEN 256 @@ -85,26 +86,28 @@ static struct { static const char *resolve_include_path(const char *path, const char *include_path) { - static char resolved_path[PATH_MAX]; - char tmp[PATH_MAX]; - const char *dir; + static std::string resolved_path; + std::string tmp; if (strstr(include_path, ".")) { warn("%s: included files may not have a file extension", include_path); return NULL; } - strcpy(tmp, path); - dir = dirname(tmp); - snprintf(resolved_path, sizeof resolved_path, "%s/%s", dir, include_path); + tmp = path; + resolved_path = dirname(tmp.data()); + resolved_path += '/'; + resolved_path += include_path; - if (!access(resolved_path, F_OK)) - return resolved_path; + if (!access(resolved_path.c_str(), F_OK)) + return resolved_path.c_str(); - snprintf(resolved_path, sizeof resolved_path, DATA_DIR"/%s", include_path); + resolved_path = DATA_DIR; + resolved_path += '/'; + resolved_path += include_path; - if (!access(resolved_path, F_OK)) - return resolved_path; + if (!access(resolved_path.c_str(), F_OK)) + return resolved_path.c_str(); return NULL; } @@ -937,7 +940,7 @@ int config_parse(struct config *config, const char *path) return -1; config_init(config); - snprintf(config->path, sizeof(config->path), "%s", path); + config->pathstr = path; return config_parse_string(config, content); } diff --git a/src/config.h b/src/config.h index e6fa062..db16f98 100644 --- a/src/config.h +++ b/src/config.h @@ -17,11 +17,6 @@ #define MAX_LAYERS 32 #define MAX_EXP_LEN 512 - -#ifndef PATH_MAX -#define PATH_MAX 1024 -#endif - #define ID_EXCLUDED 1 #define ID_MOUSE 2 #define ID_KEYBOARD 4 @@ -110,7 +105,7 @@ struct layer { }; struct config { - char path[PATH_MAX]; + std::string pathstr; struct layer layers[MAX_LAYERS]; /* Auxiliary descriptors used by layer bindings. */ diff --git a/src/daemon.cpp b/src/daemon.cpp index d22aa84..c9b3818 100644 --- a/src/daemon.cpp +++ b/src/daemon.cpp @@ -229,7 +229,7 @@ static void manage_device(struct device *dev) } keyd_log("DEVICE: g{match} %s %s\t(%s)\n", - dev->id, ent->config.path, dev->name); + dev->id, ent->config.pathstr.c_str(), dev->name); dev->data = ent->kbd.get(); } else { diff --git a/src/ipc.cpp b/src/ipc.cpp index 14e9eac..f7e37db 100644 --- a/src/ipc.cpp +++ b/src/ipc.cpp @@ -46,7 +46,6 @@ int ipc_connect() int ipc_create_server() { - char lockpath[PATH_MAX]; int sd = socket(AF_UNIX, SOCK_STREAM, 0); int lfd; struct sockaddr_un addr = {}; @@ -59,8 +58,7 @@ int ipc_create_server() } addr.sun_family = AF_UNIX; strncpy(addr.sun_path, SOCKET_PATH, sizeof(addr.sun_path)-1); - snprintf(lockpath, sizeof lockpath, "%s.lock", SOCKET_PATH); - lfd = open(lockpath, O_CREAT | O_RDONLY, 0600); + lfd = open(SOCKET_PATH ".lock", O_CREAT | O_RDONLY, 0600); if (lfd < 0) { perror("open");