From 6e8aba3714fe8ffc21dbb75ea9efdc41ab87b07f Mon Sep 17 00:00:00 2001 From: markus schnalke Date: Mon, 21 Nov 2011 11:29:03 +0100 Subject: [PATCH] Cosmetic refactoring --- sbr/m_name.c | 5 +++-- sbr/makedir.c | 55 +++++++++++++++++++++++++------------------------------ 2 files changed, 28 insertions(+), 32 deletions(-) diff --git a/sbr/m_name.c b/sbr/m_name.c index ef391e6..d42c21b 100644 --- a/sbr/m_name.c +++ b/sbr/m_name.c @@ -1,5 +1,5 @@ /* -** m_name.c -- return a message number as a string +** m_name.c -- return a message number as a string (in static memory) ** ** This code is Copyright (c) 2002, by the authors of nmh. See the ** COPYRIGHT file in the root directory of the nmh distribution for @@ -14,8 +14,9 @@ static char name[BUFSIZ]; char * m_name(int num) { - if (num <= 0) + if (num <= 0) { return "?"; + } snprintf(name, sizeof(name), "%d", num); return name; diff --git a/sbr/makedir.c b/sbr/makedir.c index 1c13bb6..d5d536c 100644 --- a/sbr/makedir.c +++ b/sbr/makedir.c @@ -68,15 +68,13 @@ makedir(char *dir) *c = '/'; } - if (!had_an_error) { - /* - ** Create the innermost nested subdirectory of the - ** path we're being asked to create. - */ - if (mkdir(dir, folder_perms) == -1) { - advise(dir, "unable to create directory"); - had_an_error = 1; - } + /* + ** Create the innermost nested subdirectory of the + ** path we're being asked to create. + */ + if (!had_an_error && mkdir(dir, folder_perms)==-1) { + advise(dir, "unable to create directory"); + had_an_error = 1; } } else { /* @@ -94,24 +92,24 @@ makedir(char *dir) ** -- Dan Harkless */ switch (pid = vfork()) { - case -1: - advise("fork", "unable to"); + case -1: + advise("fork", "unable to"); + return 0; + + case 0: + setgid(getgid()); + setuid(getuid()); + + execl("/bin/mkdir", "mkdir", dir, NULL); + execl("/usr/bin/mkdir", "mkdir", dir, NULL); + fprintf(stderr, "unable to exec "); + perror("mkdir"); + _exit(-1); + + default: + if (pidXwait(pid, "mkdir")) return 0; - - case 0: - setgid(getgid()); - setuid(getuid()); - - execl("/bin/mkdir", "mkdir", dir, NULL); - execl("/usr/bin/mkdir", "mkdir", dir, NULL); - fprintf(stderr, "unable to exec "); - perror("mkdir"); - _exit(-1); - - default: - if (pidXwait(pid, "mkdir")) - return 0; - break; + break; } chmod(dir, folder_perms); @@ -119,8 +117,5 @@ makedir(char *dir) umask(saved_umask); /* put the user's umask back */ - if (had_an_error) - return 0; /* opposite of UNIX error return convention */ - else - return 1; + return (had_an_error) ? 0 : 1; } -- 1.7.10.4