env.c: use buffer.h
This commit is contained in:
parent
710f761cc6
commit
6456ac58bc
2 changed files with 11 additions and 13 deletions
6
Makefile
6
Makefile
|
|
@ -10,9 +10,9 @@ all : $(PROGRAMS)
|
||||||
install : $(PROGRAMS)
|
install : $(PROGRAMS)
|
||||||
cp $^ $(HOME)/bin/
|
cp $^ $(HOME)/bin/
|
||||||
|
|
||||||
dlight : dlight.o env.o http.o rss.o lockfile.o filter.o cconf.o dlhist.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 env.o lockfile.o filter.o cconf.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 env.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-filter-check: filter-check.o filter.o error.o
|
||||||
|
|
||||||
dlight-% : %.o
|
dlight-% : %.o
|
||||||
|
|
|
||||||
18
env.c
18
env.c
|
|
@ -24,29 +24,27 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
|
#include "buffer.h"
|
||||||
#include "env.h"
|
#include "env.h"
|
||||||
|
|
||||||
static char base[4096];
|
static char *base = NULL;
|
||||||
|
|
||||||
static void get_base() {
|
static void get_base() {
|
||||||
|
|
||||||
char *ptr;
|
struct buffer buf = BUFFER_INIT;
|
||||||
int len;
|
char *ptr = getenv("HOME");
|
||||||
|
|
||||||
ptr = getenv("HOME");
|
|
||||||
if (!ptr)
|
if (!ptr)
|
||||||
ptr = ".";
|
ptr = ".";
|
||||||
|
buffer_append_str(&buf, ptr);
|
||||||
|
buffer_append_str(&buf, "/.dlight");
|
||||||
|
|
||||||
len = strlen(ptr);
|
base = buffer_cstr_release(&buf);
|
||||||
if (len < sizeof(base) - 9) {
|
|
||||||
memcpy(base, ptr, len);
|
|
||||||
memcpy(base+len, "/.dlight", 9);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* env_get_dir() {
|
const char* env_get_dir() {
|
||||||
|
|
||||||
if (!*base) {
|
if (!base) {
|
||||||
get_base();
|
get_base();
|
||||||
if (mkdir(base, 0700) < 0 && errno != EEXIST) {
|
if (mkdir(base, 0700) < 0 && errno != EEXIST) {
|
||||||
fatal("Unable to create '%s': %s\n",
|
fatal("Unable to create '%s': %s\n",
|
||||||
|
|
|
||||||
Reference in a new issue