diff --git a/Makefile b/Makefile index 65064b0..8a8468e 100644 --- a/Makefile +++ b/Makefile @@ -10,9 +10,9 @@ all : $(PROGRAMS) install : $(PROGRAMS) cp $^ $(HOME)/bin/ -dlight : dlight.o env.o http.o rss.o lockfile.o filter.o cconf.o dlhist.o error.o -dlight-compile : compile.o env.o lockfile.o filter.o cconf.o error.o -dlight-read-config : read-config.o env.o cconf.o error.o +dlight : dlight.o buffer.o env.o http.o rss.o lockfile.o filter.o cconf.o dlhist.o error.o +dlight-compile : compile.o buffer.o env.o lockfile.o filter.o cconf.o error.o +dlight-read-config : read-config.o buffer.o env.o cconf.o error.o dlight-filter-check: filter-check.o filter.o error.o dlight-% : %.o diff --git a/env.c b/env.c index be2a228..1755970 100644 --- a/env.c +++ b/env.c @@ -24,29 +24,27 @@ #include #include #include "error.h" +#include "buffer.h" #include "env.h" -static char base[4096]; +static char *base = NULL; static void get_base() { - char *ptr; - int len; + struct buffer buf = BUFFER_INIT; + char *ptr = getenv("HOME"); - ptr = getenv("HOME"); if (!ptr) ptr = "."; + buffer_append_str(&buf, ptr); + buffer_append_str(&buf, "/.dlight"); - len = strlen(ptr); - if (len < sizeof(base) - 9) { - memcpy(base, ptr, len); - memcpy(base+len, "/.dlight", 9); - } + base = buffer_cstr_release(&buf); } const char* env_get_dir() { - if (!*base) { + if (!base) { get_base(); if (mkdir(base, 0700) < 0 && errno != EEXIST) { fatal("Unable to create '%s': %s\n",