]> mj.ucw.cz Git - libucw.git/blob - lib/exitstatus.c
increase buffer 3x
[libucw.git] / lib / exitstatus.c
1 /*
2  *      UCW Library -- Formatting of Process Exit Status
3  *
4  *      (c) 2004 Martin Mares <mj@ucw.cz>
5  *
6  *      This software may be freely distributed and used according to the terms
7  *      of the GNU Lesser General Public License.
8  */
9
10 #include "lib/lib.h"
11
12 #include <stdio.h>
13 #include <sys/wait.h>
14 #include <errno.h>
15
16 int
17 format_exit_status(byte *msg, int stat)
18 {
19   if (stat < 0)
20     sprintf(msg, "failed to fork (err=%d)", errno);
21   else if (WIFEXITED(stat) && WEXITSTATUS(stat) < 256)
22     {
23       if (WEXITSTATUS(stat))
24         sprintf(msg, "died with exit code %d", WEXITSTATUS(stat));
25       else
26         {
27           msg[0] = 0;
28           return 0;
29         }
30     }
31   else if (WIFSIGNALED(stat))
32     sprintf(msg, "died on signal %d", WTERMSIG(stat));
33   else
34     sprintf(msg, "died with status %x", stat);
35   return 1;
36 }