X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=sbr%2Fcontext_read.c;h=cfdcff275c11192a2c753a68084452557d9fb8a9;hp=166fe592906174795b39e2d167190f1cea1d095a;hb=5cb46b33551f28e4168989e752e09bd927e993f9;hpb=2abb9a7cfb0930e27062088734d306e7d78e4cc2 diff --git a/sbr/context_read.c b/sbr/context_read.c index 166fe59..cfdcff2 100644 --- a/sbr/context_read.c +++ b/sbr/context_read.c @@ -25,10 +25,12 @@ */ #include /* mh internals */ +#include #include /* system call errors */ #include /* structure for getpwuid() results */ #include #include +#include void context_read(void) @@ -37,8 +39,8 @@ context_read(void) char *cp; /* miscellaneous pointer */ char *nd; /* nmh directory pointer */ struct stat st; /* stat() results */ - register struct passwd *pw; /* getpwuid() results */ - register FILE *ib; /* profile and context file pointer */ + struct passwd *pw; /* getpwuid() results */ + FILE *ib; /* profile and context file pointer */ /* ** If this routine _is_ called again (despite the wanings in the @@ -54,7 +56,7 @@ context_read(void) */ if (!(mypath = getenv("HOME"))) { if (!(pw = getpwuid(getuid())) || !*pw->pw_dir) { - adios(NULL, "cannot determine your home directory"); + adios(EX_OSERR, NULL, "cannot determine your home directory"); } mypath = pw->pw_dir; } @@ -63,14 +65,14 @@ context_read(void) ** set mmhpath */ if ((cp = getenv("MMH")) && *cp) { - mmhpath = getcpy(expanddir(cp)); /* rel to cwd */ + mmhpath = mh_xstrdup(expanddir(cp)); /* rel to cwd */ if (stat(mmhpath, &st) != -1 && (st.st_mode & S_IFDIR) == 0) { - adios(NULL, "`%s' specified by your MMH environment variable is not a directory", cp); + adios(EX_CONFIG, NULL, "`%s' specified by your MMH environment variable is not a directory", cp); } } else { mmhpath = concat(mypath, "/", mmhdir, NULL); if (stat(mmhpath, &st) == -1 || (st.st_mode & S_IFDIR) == 0) { - adios(NULL, "Doesn't look like mmh is set up for your account. Run `mmh' to do so."); + adios(EX_CONFIG, NULL, "Doesn't look like mmh is set up for your account. Run `mmh' to do so."); } } @@ -81,20 +83,20 @@ context_read(void) */ if ((cp = getenv("MMHP")) && *cp) { if (*cp == '/') { - defpath = getcpy(cp); + defpath = mh_xstrdup(cp); } else { defpath = concat(mmhpath, "/", cp, NULL); } if (stat(defpath, &st) != -1 && (st.st_mode & S_IFREG) == 0) { - adios(NULL, "Your profile `%s', specified by the MMHP environment variable, is not a normal file", cp); + adios(EX_CONFIG, NULL, "Your profile `%s', specified by the MMHP environment variable, is not a normal file", cp); } if ((ib = fopen(defpath, "r")) == (FILE *)0) { - adios(NULL, "Unable to read your profile `%s', specified by the MMHP environment variable", defpath); + adios(EX_IOERR, NULL, "Unable to read your profile `%s', specified by the MMHP environment variable", defpath); } } else { defpath = concat(mmhpath, "/", profile, NULL); if ((ib = fopen(defpath, "r")) == (FILE *)0) { - adios(NULL, "No profile found. Please create `%s' first.", defpath); + adios(EX_CONFIG, NULL, "No profile found. Please create `%s' first.", defpath); } cp = profile; } @@ -107,10 +109,10 @@ context_read(void) ** to an absolute one rooted in the home directory. */ if ((cp = context_find("path")) == NULL) { - adios(NULL, "Your profile `%s' does not contain the required path entry.", defpath); + adios(EX_CONFIG, NULL, "Your profile `%s' does not contain the required path entry.", defpath); } if (!*cp) { - adios(NULL, "The Path entry of your profile `%s' must be non-empty.", defpath); + adios(EX_CONFIG, NULL, "The Path entry of your profile `%s' must be non-empty.", defpath); } if (*cp == '/') { nd = cp; @@ -119,18 +121,18 @@ context_read(void) } if (stat(nd, &st) == -1) { if (errno != ENOENT) { - adios(nd, "error opening"); + adios(EX_IOERR, nd, "error opening"); } cp = concat("Your mail storage directory `", nd, "' doesn't exist; Create it? ", NULL); if (!getanswer(cp)) { - adios(NULL, "Unable to access the mail storage directory `%s'", nd); + adios(EX_NOPERM, NULL, "Unable to access the mail storage directory `%s'", nd); } - free(cp); + mh_free0(&cp); if (!makedir(nd)) { - adios(nd, "unable to create"); + adios(EX_CANTCREAT, nd, "unable to create"); } } else if ((st.st_mode & S_IFDIR) == 0) { - adios(NULL, "Your mail storage `%s' is not a directory", nd); + adios(EX_DATAERR, NULL, "Your mail storage `%s' is not a directory", nd); } /* ** Create the default folder (inbox) @@ -138,10 +140,10 @@ context_read(void) cp = toabsdir(defaultfolder); if (stat(cp, &st) == -1) { if (!makedir(cp)) { - adios(cp, "Unable to create the default folder"); + adios(EX_CANTCREAT, cp, "Unable to create the default folder"); } } else if ((st.st_mode & S_IFDIR) == 0) { - adios(NULL, "The default folder `%s' is not a directory", cp); + adios(EX_DATAERR, NULL, "The default folder `%s' is not a directory", cp); } /* @@ -167,7 +169,7 @@ context_read(void) } if (*cp == '/') { - ctxpath = getcpy(cp); + ctxpath = mh_xstrdup(cp); } else { ctxpath = concat(mmhpath, "/", cp, NULL); }