updated on Thu Jan 12 04:00:44 UTC 2012
[aur-mirror.git] / dmenu-hg-xdg / xdgbasedir.patch
blob1f5dd0c390b27f160b8b98fda64c12f103e71919
1 diff -r 2b9683c50723 config.mk
2 --- a/config.mk Wed Dec 01 20:25:10 2010 +0000
3 +++ b/config.mk Thu Dec 30 12:37:58 2010 -0700
4 @@ -14,12 +14,16 @@
5 XINERAMALIBS = -lXinerama
6 XINERAMAFLAGS = -DXINERAMA
8 +# XDG path stuff, comment if you don't want it
9 +XDGBASEDIRLIBS = "-lxdg-basedir"
10 +XDGBASEDIRFLAGS = "-DXDGBASEDIR"
12 # includes and libs
13 INCS = -I${X11INC}
14 -LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS}
15 +LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${XDGBASEDIRLIBS}
17 # flags
18 -CPPFLAGS = -D_BSD_SOURCE -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
19 +CPPFLAGS = -D_BSD_SOURCE -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS} ${XDGBASEDIRFLAGS}
20 CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
21 LDFLAGS = -s ${LIBS}
23 diff -r 2b9683c50723 dmenu_path.c
24 --- a/dmenu_path.c Wed Dec 01 20:25:10 2010 +0000
25 +++ b/dmenu_path.c Thu Dec 30 12:37:58 2010 -0700
26 @@ -7,12 +7,24 @@
27 #include <unistd.h>
28 #include <sys/stat.h>
30 -#define CACHE ".dmenu_cache"
31 +#ifdef XDGBASEDIR
32 + #include <basedir.h>
33 + #include <basedir_fs.h>
34 + #include <errno.h>
36 + #define CACHEDIR "/dmenu"
37 + #define CACHEFILE "/path.cache"
39 + static char *cachefile;
40 +#else
41 + #define CACHE ".dmenu_cache"
42 +#endif
44 static void die(const char *s);
45 static int qstrcmp(const void *a, const void *b);
46 static void scan(void);
47 static int uptodate(void);
48 +static const char * getCacheFile(void);
50 static char **items = NULL;
51 static const char *home, *path;
52 @@ -26,7 +38,7 @@
53 if(chdir(home) < 0)
54 die("chdir failed");
55 if(uptodate()) {
56 - execlp("cat", "cat", CACHE, NULL);
57 + execlp("cat", "cat", getCacheFile(), NULL);
58 die("exec failed");
60 scan();
61 @@ -71,7 +83,7 @@
62 closedir(dp);
64 qsort(items, count, sizeof *items, qstrcmp);
65 - if(!(cache = fopen(CACHE, "w")))
66 + if(!(cache = fopen(getCacheFile(), "w")))
67 die("open failed");
68 for(i = 0; i < count; i++) {
69 if(i > 0 && !strcmp(items[i], items[i-1]))
70 @@ -89,7 +101,7 @@
71 time_t mtime;
72 struct stat st;
74 - if(stat(CACHE, &st) < 0)
75 + if(stat(getCacheFile(), &st) < 0)
76 return 0;
77 mtime = st.st_mtime;
78 if(!(p = strdup(path)))
79 @@ -100,3 +112,33 @@
80 free(p);
81 return 1;
84 +const char *
85 +getCacheFile(void) {
86 +#ifdef XDGBASEDIR
87 + if (cachefile == NULL) {
88 + xdgHandle* handle;
89 + char cachepath[256];
91 + handle = xdgInitHandle(malloc(sizeof(xdgHandle)));
93 + strncpy(cachepath, xdgCacheHome(handle), 256);
94 + strcat(cachepath, CACHEDIR);
96 + int ret = xdgMakePath(cachepath, 0755);
97 + if (ret < 0 && errno != EEXIST) {
98 + perror("couldn't make path");
99 + exit(errno);
102 + strcat(cachepath, CACHEFILE);
104 + cachefile = malloc(strlen(cachepath) * sizeof(char));
105 + strncpy(cachefile, cachepath, strlen(cachepath));
108 + return cachefile;
109 +#else
110 + return CACHE;
111 +#endif