home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib25.zoo / waitpid.c < prev    next >
C/C++ Source or Header  |  1992-09-30  |  1KB  |  61 lines

  1. /* waitpid() emulation for MiNT, by Howard Chu. From wait3.c by Eric R. Smith
  2.  */
  3.  
  4. #include <types.h>
  5. #include <wait.h>
  6. #include <time.h>
  7. #include <resource.h>
  8. #include <mintbind.h>
  9. #include <errno.h>
  10. #include <signal.h>
  11.  
  12. extern int __mint;
  13.  
  14. extern long __waitval;        /* in thread.c */
  15.  
  16. int
  17. waitpid(pid, status, options)
  18.     pid_t pid;
  19.     union wait *status;
  20.     int options;
  21. {
  22.     long r;
  23.     int exit_status, sig_term;
  24.  
  25.     if (__mint == 0) {
  26.         r = __waitval;
  27.         __waitval = -ENOENT;
  28.     } else
  29.         r = Pwaitpid(pid, options, 0L);
  30.     if (r < 0) {
  31.         errno = (int) -r;
  32.         return -1;
  33.     }
  34.     pid = (int) ((r & 0xffff0000L) >> 16);
  35.     if (pid) {
  36.         status->_i = 0;
  37.  
  38.         if ( ((short)r) == -32) {
  39.             sig_term = SIGINT;
  40.             exit_status = 0;
  41.         }
  42.         else {
  43.             exit_status = (int) (r & 0x000000ffL);
  44.             sig_term = (int) ((r & 0x00007f00L) >> 8);
  45.         }
  46.         if (sig_term && exit_status != 0 && exit_status != 0177)
  47.             sig_term = 0;
  48.         if (exit_status == 0177 && sig_term) {
  49.             status->w_termsig = WSTOPPED;
  50.             status->w_stopsig = sig_term;
  51.         }
  52.         else {
  53.             status->w_termsig = sig_term;
  54.             status->w_retcode = exit_status;
  55.         }
  56.         status->w_coredump = 0;
  57.  
  58.     }
  59.     return pid;
  60. }
  61.