X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=dmenu_path.c;h=407477a5703002f335ce70aace15c4136fe7f0ca;hb=86468aafe52a94ce6ba1a3601a587c65724a61aa;hp=1575f1d193524e7e582ddcf6cef3e0efd6ce7fdd;hpb=bf7b8e37ee2a53f0f1bed75dd84e5214269cfac8;p=dmenu.git diff --git a/dmenu_path.c b/dmenu_path.c index 1575f1d..407477a 100644 --- a/dmenu_path.c +++ b/dmenu_path.c @@ -1,32 +1,30 @@ /* See LICENSE file for copyright and license details. */ #include +#include #include #include #include #include #include -#define CACHE ".dmenu_cache" - -static int qstrcmp(const void *a, const void *b); static void die(const char *s); +static int qstrcmp(const void *a, const void *b); static void scan(void); static int uptodate(void); static char **items = NULL; -static const char *Home, *Path; -static size_t count = 0; +static const char *home, *path; int main(void) { - if(!(Home = getenv("HOME"))) + if(!(home = getenv("HOME"))) die("no $HOME"); - if(!(Path = getenv("PATH"))) + if(!(path = getenv("PATH"))) die("no $PATH"); - if(chdir(Home) < 0) + if(chdir(home) < 0) die("chdir failed"); if(uptodate()) { - execlp("cat", "cat", CACHE, NULL); + execl("/bin/cat", "cat", CACHE, NULL); die("exec failed"); } scan(); @@ -47,15 +45,16 @@ qstrcmp(const void *a, const void *b) { void scan(void) { char buf[PATH_MAX]; - char *dir, *path; - size_t i; + char *dir, *p; + size_t i, count; struct dirent *ent; DIR *dp; FILE *cache; - if(!(path = strdup(Path))) + count = 0; + if(!(p = strdup(path))) die("strdup failed"); - for(dir = strtok(path, ":"); dir; dir = strtok(NULL, ":")) { + for(dir = strtok(p, ":"); dir; dir = strtok(NULL, ":")) { if(!(dp = opendir(dir))) continue; while((ent = readdir(dp))) { @@ -79,23 +78,23 @@ scan(void) { fprintf(stdout, "%s\n", items[i]); } fclose(cache); - free(path); + free(p); } int uptodate(void) { - char *dir, *path; + char *dir, *p; time_t mtime; struct stat st; if(stat(CACHE, &st) < 0) return 0; mtime = st.st_mtime; - if(!(path = strdup(Path))) + if(!(p = strdup(path))) die("strdup failed"); - for(dir = strtok(path, ":"); dir; dir = strtok(NULL, ":")) + for(dir = strtok(p, ":"); dir; dir = strtok(NULL, ":")) if(!stat(dir, &st) && st.st_mtime > mtime) return 0; - free(path); + free(p); return 1; }