about summary refs log tree commit diff
path: root/seq.c
diff options
context:
space:
mode:
authorIvy Foster <ivy.foster@gmail.com>2016-09-01 18:50:20 -0500
committerIvy Foster <ivy.foster@gmail.com>2016-09-01 18:50:20 -0500
commitca8cef1660ad89ab488a22dc50eeb7cd77222c6e (patch)
tree625d716bafdf3a46c16dffbf4dfddc2a2ef02d03 /seq.c
parent8d3fa82d8246a08d2c7899963ad7cf61b7a4563c (diff)
downloadmblaze-ca8cef1660ad89ab488a22dc50eeb7cd77222c6e.tar.gz
mblaze-ca8cef1660ad89ab488a22dc50eeb7cd77222c6e.tar.xz
mblaze-ca8cef1660ad89ab488a22dc50eeb7cd77222c6e.zip
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.
Diffstat (limited to 'seq.c')
-rw-r--r--seq.c16
1 files changed, 12 insertions, 4 deletions
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