python3Packages.orjson: Disable failing tests on 32 bit
[NixPkgs.git] / pkgs / misc / drivers / spacenavd / configure-cfgfile-path.patch
blob268282e96eae666687f545438078e53c24a8ac98
1 diff --git a/src/spnavd.c b/src/spnavd.c
2 index 2d4eca6..a5227ed 100644
3 --- a/src/spnavd.c
4 +++ b/src/spnavd.c
5 @@ -27,6 +27,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
6 #include <sys/select.h>
7 #include <sys/socket.h>
8 #include <sys/un.h>
9 +#include <sys/types.h>
10 +#include <pwd.h>
11 #include "spnavd.h"
12 #include "logger.h"
13 #include "dev.h"
14 @@ -47,13 +49,39 @@ static void handle_events(fd_set *rset);
15 static void sig_handler(int s);
16 static char *fix_path(char *str);
18 -static char *cfgfile = DEF_CFGFILE;
19 +static char* config_path;
20 +char* cfg_path()
22 + char* buf;
23 + if((buf = getenv("XDG_CONFIG_HOME"))) {
24 + if(config_path == NULL) {
25 + config_path = malloc(strlen(buf) + strlen("/spnavrc") + 1);
26 + if ( config_path != NULL) {
27 + sprintf(config_path, "%s/spnavrc", buf);
28 + }
29 + };
30 + return config_path;
31 + } else {
32 + if (!(buf = getenv("HOME"))) {
33 + struct passwd *pw = getpwuid(getuid());
34 + buf = pw->pw_dir;
35 + }
36 + config_path = malloc(strlen(buf) + strlen("/.config/spnavrc") + 1);
37 + if ( config_path != NULL) {
38 + sprintf(config_path, "%s/.config/spnavrc", buf);
39 + }
40 + return config_path;
41 + }
44 +static char *cfgfile = NULL;
45 static char *logfile = DEF_LOGFILE;
46 static char *pidpath = NULL;
48 int main(int argc, char **argv)
50 int i, pid, ret, become_daemon = 1;
51 + cfgfile = cfg_path();
53 for(i=1; i<argc; i++) {
54 if(argv[i][0] == '-') {
55 @@ -247,7 +275,7 @@ static void print_usage(const char *argv0)
56 printf("usage: %s [options]\n", argv0);
57 printf("options:\n");
58 printf(" -d: do not daemonize\n");
59 - printf(" -c <file>: config file path (default: " DEF_CFGFILE ")\n");
60 + printf(" -c <file>: config file path (default: %s)\n", cfg_path());
61 printf(" -l <file>|syslog: log file path or log to syslog (default: " DEF_LOGFILE ")\n");
62 printf(" -v: verbose output\n");
63 printf(" -V,-version: print version number and exit\n");