Die on fork() failure (thanks Evil_Bob) - noice - small file browser (mirror / fork from 2f30.org)
 (HTM) git clone git://git.codemadness.org/noice
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit e81a1c5362dc178e1c9006077f836d7ca5bfb577
 (DIR) parent 86fa68dc89e87d10748ceb642e4d766e9f2b749b
 (HTM) Author: sin <sin@2f30.org>
       Date:   Sun,  4 Aug 2019 11:53:02 +0100
       
       Die on fork() failure (thanks Evil_Bob)
       
       Diffstat:
         M spawn.c                             |       8 ++++++--
       
       1 file changed, 6 insertions(+), 2 deletions(-)
       ---
 (DIR) diff --git a/spawn.c b/spawn.c
       @@ -2,6 +2,7 @@
        #include <sys/types.h>
        #include <sys/wait.h>
        
       +#include <err.h>
        #include <stdarg.h>
        #include <unistd.h>
        
       @@ -14,12 +15,15 @@ spawnvp(char *dir, char *file, char *argv[])
                int status;
        
                pid = fork();
       -        if (pid == 0) {
       +        switch (pid) {
       +        case -1:
       +                err(1, "fork");
       +        case 0:
                        if (dir != NULL)
                                chdir(dir);
                        execvp(file, argv);
                        _exit(1);
       -        } else {
       +        default:
                        /* Ignore interruptions */
                        while (waitpid(pid, &status, 0) == -1)
                                ;