Cosmetic refactoring
authormarkus schnalke <meillo@marmaro.de>
Mon, 21 Nov 2011 10:29:03 +0000 (11:29 +0100)
committermarkus schnalke <meillo@marmaro.de>
Mon, 21 Nov 2011 10:29:03 +0000 (11:29 +0100)
sbr/m_name.c
sbr/makedir.c

index ef391e6..d42c21b 100644 (file)
@@ -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;
index 1c13bb6..d5d536c 100644 (file)
@@ -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 <dan-nmh@dilvish.speed.net>
                */
                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;
 }