aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dmenu_path.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/dmenu_path.c b/dmenu_path.c
index 1575f1d..15d0da0 100644
--- a/dmenu_path.c
+++ b/dmenu_path.c
@@ -8,22 +8,21 @@
8 8
9#define CACHE ".dmenu_cache" 9#define CACHE ".dmenu_cache"
10 10
11static int qstrcmp(const void *a, const void *b);
12static void die(const char *s); 11static void die(const char *s);
12static int qstrcmp(const void *a, const void *b);
13static void scan(void); 13static void scan(void);
14static int uptodate(void); 14static int uptodate(void);
15 15
16static char **items = NULL; 16static char **items = NULL;
17static const char *Home, *Path; 17static const char *home, *path;
18static size_t count = 0;
19 18
20int 19int
21main(void) { 20main(void) {
22 if(!(Home = getenv("HOME"))) 21 if(!(home = getenv("HOME")))
23 die("no $HOME"); 22 die("no $HOME");
24 if(!(Path = getenv("PATH"))) 23 if(!(path = getenv("PATH")))
25 die("no $PATH"); 24 die("no $PATH");
26 if(chdir(Home) < 0) 25 if(chdir(home) < 0)
27 die("chdir failed"); 26 die("chdir failed");
28 if(uptodate()) { 27 if(uptodate()) {
29 execlp("cat", "cat", CACHE, NULL); 28 execlp("cat", "cat", CACHE, NULL);
@@ -47,15 +46,16 @@ qstrcmp(const void *a, const void *b) {
47void 46void
48scan(void) { 47scan(void) {
49 char buf[PATH_MAX]; 48 char buf[PATH_MAX];
50 char *dir, *path; 49 char *dir, *p;
51 size_t i; 50 size_t i, count;
52 struct dirent *ent; 51 struct dirent *ent;
53 DIR *dp; 52 DIR *dp;
54 FILE *cache; 53 FILE *cache;
55 54
56 if(!(path = strdup(Path))) 55 count = 0;
56 if(!(p = strdup(path)))
57 die("strdup failed"); 57 die("strdup failed");
58 for(dir = strtok(path, ":"); dir; dir = strtok(NULL, ":")) { 58 for(dir = strtok(p, ":"); dir; dir = strtok(NULL, ":")) {
59 if(!(dp = opendir(dir))) 59 if(!(dp = opendir(dir)))
60 continue; 60 continue;
61 while((ent = readdir(dp))) { 61 while((ent = readdir(dp))) {
@@ -79,23 +79,23 @@ scan(void) {
79 fprintf(stdout, "%s\n", items[i]); 79 fprintf(stdout, "%s\n", items[i]);
80 } 80 }
81 fclose(cache); 81 fclose(cache);
82 free(path); 82 free(p);
83} 83}
84 84
85int 85int
86uptodate(void) { 86uptodate(void) {
87 char *dir, *path; 87 char *dir, *p;
88 time_t mtime; 88 time_t mtime;
89 struct stat st; 89 struct stat st;
90 90
91 if(stat(CACHE, &st) < 0) 91 if(stat(CACHE, &st) < 0)
92 return 0; 92 return 0;
93 mtime = st.st_mtime; 93 mtime = st.st_mtime;
94 if(!(path = strdup(Path))) 94 if(!(p = strdup(path)))
95 die("strdup failed"); 95 die("strdup failed");
96 for(dir = strtok(path, ":"); dir; dir = strtok(NULL, ":")) 96 for(dir = strtok(p, ":"); dir; dir = strtok(NULL, ":"))
97 if(!stat(dir, &st) && st.st_mtime > mtime) 97 if(!stat(dir, &st) && st.st_mtime > mtime)
98 return 0; 98 return 0;
99 free(path); 99 free(p);
100 return 1; 100 return 1;
101} 101}