home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib32.zoo / waitpid.c < prev    next >
C/C++ Source or Header  |  1993-05-16  |  1KB  |  66 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. pid_t
  17. waitpid(pid, status, options)
  18.     pid_t pid;
  19.     int *status;
  20.     int options;
  21. {
  22.     long r;
  23.     int exit_status, sig_term;
  24.     union wait *statwait;
  25.  
  26.     statwait = (union wait *) status;
  27.     if (__mint == 0) {
  28.         r = __waitval;
  29.         __waitval = -ENOENT;
  30.     } else
  31.         r = Pwaitpid(pid, options, 0L);
  32.     if (r < 0) {
  33.         errno = (int) -r;
  34.         return -1;
  35.     }
  36.     pid = (int) ((r & 0xffff0000L) >> 16);
  37.     if (pid) {
  38.       if (statwait)
  39.         {
  40.         statwait->_i = 0;
  41.  
  42.         if ( ((short)r) == -32) {
  43.             sig_term = SIGINT;
  44.             exit_status = 0;
  45.         }
  46.         else {
  47.             exit_status = (int) (r & 0x000000ffL);
  48.             sig_term = (int) ((r & 0x00007f00L) >> 8);
  49.         }
  50.         if (sig_term >= NSIG)
  51.           sig_term = 0;
  52.         if (sig_term && exit_status != 0 && exit_status != 0177)
  53.             sig_term = 0;
  54.         if (exit_status == 0177 && sig_term) {
  55.             statwait->w_termsig = WSTOPPED;
  56.             statwait->w_stopsig = sig_term;
  57.         }
  58.         else {
  59.             statwait->w_termsig = sig_term;
  60.             statwait->w_retcode = exit_status;
  61.         }
  62.         }
  63.     }
  64.     return pid;
  65. }
  66.