/*
   <p>Decode <i>waitpid()</i> replies.</p>

   <kbd>
   <b>environ - C programming support functions</b><br>
   Copyright (C) 2005  Martin C Gregorie
   
   This program is free software; you can redistribute it and/or
   modify it under the terms of the Lesser GNU General Public License.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
  
   You should have received a copy of the Lesser GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
   </kbd>
  
   <p>Contact Martin Gregorie at <i>martin@gregorie.org</i></p>
*/

#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <environ.h>

#define STATBUFF  80

/*
   Decode a <i>waitpid()</i> reply.
   This decodes the value in <u>status</u> and returns a string
   containing the decoded reply.
*/
char *prstat(int status)
{
   static char buff[STATBUFF];
   
   if (WIFEXITED(status))
      snprintf(buff, STATBUFF, "Normal exit - %d", WEXITSTATUS(status));
   else
   if (WIFSIGNALED(status))
      snprintf(buff,
               STATBUFF,
               "Abnormal exit - signal %d (%s)",
               WTERMSIG(status),
               strsignal(WTERMSIG(status)));
   else
   if (WIFSTOPPED(status))
      snprintf(buff, 
               STATBUFF,
               "Stopped - signal %d (%s)",
               WSTOPSIG(status),
               strsignal(WSTOPSIG(status)));
   else
      snprintf(buff,
               STATBUFF,
               "Process continues - status = %d",
               status);

   return(buff);
}
