From ca8cef1660ad89ab488a22dc50eeb7cd77222c6e Mon Sep 17 00:00:00 2001 From: Ivy Foster Date: Thu, 1 Sep 2016 18:50:20 -0500 Subject: Add $MBLAZE environment variable to set profile location As a side benefit, all callers of blaze822_home_file need only pass the filename, so the base directory is set in only one place. --- seq.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'seq.c') diff --git a/seq.c b/seq.c index 159c81c..3cbf131 100644 --- a/seq.c +++ b/seq.c @@ -21,6 +21,14 @@ blaze822_home_file(char *basename) { static char path[PATH_MAX]; static char *homedir; + static char *profile; + + if (!profile) + profile = getenv("MBLAZE"); + if (profile) { + snprintf(path, sizeof path, "%s/%s", profile, basename); + return path; + } if (!homedir) homedir = getenv("HOME"); @@ -34,7 +42,7 @@ blaze822_home_file(char *basename) if (!homedir) return "/dev/null/homeless"; - snprintf(path, sizeof path, "%s/%s", homedir, basename); + snprintf(path, sizeof path, "%s/.mblaze/%s", homedir, basename); return path; } @@ -49,7 +57,7 @@ blaze822_seq_open(char *file) if (!file) file = getenv("MAILSEQ"); if (!file) - file = blaze822_home_file(".mblaze/seq"); + file = blaze822_home_file("seq"); fd = open(file, O_RDONLY); if (!fd) return 0; @@ -138,7 +146,7 @@ blaze822_seq_cur(void) char *curlink = getenv("MAILCUR"); if (!curlink) - curlink = blaze822_home_file(".mblaze/cur"); + curlink = blaze822_home_file("cur"); int r = readlink(curlink, b, sizeof b - 1); if (r < 0) @@ -157,7 +165,7 @@ blaze822_seq_setcur(char *s) char curtmplink[PATH_MAX]; char *curlink = getenv("MAILCUR"); if (!curlink) - curlink = blaze822_home_file(".mblaze/cur"); + curlink = blaze822_home_file("cur"); if (snprintf(curtmplink, sizeof curtmplink, "%s-", curlink) >= PATH_MAX) return -1; // truncation -- cgit 1.4.1