Rearranged whitespace (and comments) in all the code!
[mmh] / sbr / pidstatus.c
1 /*
2  * pidstatus.c -- report child's status
3  *
4  * This code is Copyright (c) 2002, by the authors of nmh.  See the
5  * COPYRIGHT file in the root directory of the nmh distribution for
6  * complete copyright information.
7  */
8
9 #include <h/mh.h>
10
11 /*
12  * auto-generated header
13  */
14 #include <sigmsg.h>
15
16 #ifdef HAVE_SYS_WAIT_H
17 # include <sys/wait.h>
18 #endif
19
20 #ifndef WTERMSIG
21 # define WTERMSIG(s) ((int)((s) & 0x7F))
22 #endif
23
24 #ifndef WCOREDUMP
25 # define WCOREDUMP(s) ((s) & 0x80)
26 #endif
27
28 int
29 pidstatus (int status, FILE *fp, char *cp)
30 {
31         int signum;
32
33         /*
34          * I have no idea what this is for (rc)
35          * so I'm commenting it out for right now.
36          *
37          *  if ((status & 0xff00) == 0xff00)
38          *      return status;
39          */
40
41         /* If child process returned normally */
42         if (WIFEXITED(status)) {
43                 if ((signum = WEXITSTATUS(status))) {
44                         if (cp)
45                                 fprintf (fp, "%s: ", cp);
46                         fprintf (fp, "exit %d\n", signum);
47                 }
48         } else if (WIFSIGNALED(status)) {
49                 /* If child process terminated due to receipt of a signal */
50                 signum = WTERMSIG(status);
51                 if (signum != SIGINT) {
52                         if (cp)
53                                 fprintf (fp, "%s: ", cp);
54                         fprintf (fp, "signal %d", signum);
55                         if (signum >= 0 && signum < sizeof(sigmsg) && sigmsg[signum] != NULL)
56                                 fprintf (fp, " (%s%s)\n", sigmsg[signum],
57                                          WCOREDUMP(status) ? ", core dumped" : "");
58                         else
59                                 fprintf (fp, "%s\n", WCOREDUMP(status) ? " (core dumped)" : "");
60                 }
61         }
62
63         return status;
64 }