home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tkisrc04.zip / tcl / os2 / tclOS2Util.c < prev    next >
C/C++ Source or Header  |  1998-08-07  |  2KB  |  74 lines

  1. /* 
  2.  * tclOS2Util.c --
  3.  *
  4.  *    This file contains a collection of utility procedures that
  5.  *    are present in Tcl's OS/2 core but not in the generic core.
  6.  *    For example, they do file manipulation and process manipulation.
  7.  *
  8.  * Copyright (c) 1996-1997 Illya Vaes
  9.  * Copyright (c) 1994 Sun Microsystems, Inc.
  10.  *
  11.  * See the file "license.terms" for information on usage and redistribution
  12.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  13.  */
  14.  
  15. #define INCL_BASE /*MM*/
  16. #include <os2.h> /*MM*/
  17. #include "tclInt.h"
  18. #include "tclPort.h"
  19.  
  20.  
  21. /*
  22.  *----------------------------------------------------------------------
  23.  *
  24.  * Tcl_WaitPid --
  25.  *
  26.  *    Does the waitpid system call.
  27.  *
  28.  * Results:
  29.  *    Returns return value of pid it's waiting for.
  30.  *
  31.  * Side effects:
  32.  *    None.
  33.  *
  34.  *----------------------------------------------------------------------
  35.  */
  36. int
  37. Tcl_WaitPid(pid, statPtr, options)
  38.     pid_t pid;
  39.     int *statPtr;
  40.     int options;
  41. {
  42.     ULONG flags;
  43.     APIRET ret;
  44.     struct _RESULTCODES results; /*MM*/
  45.  
  46.     if (options & WNOHANG) {
  47.     flags = DCWW_NOWAIT;
  48.     } else {
  49.     flags = DCWW_WAIT;
  50.     }
  51. #ifdef DEBUG
  52.     printf("Waiting for PID %d (%s)", pid,
  53.            options & WNOHANG ? "WNOHANG" : "WAIT");
  54. #endif
  55. /*MM* add { */
  56. #ifdef __IBMC__
  57.     DosWaitChild(DCWA_PROCESS, flags, &results, &ret, pid);
  58.      *statPtr = results.codeTerminate & 0xFF | (results.codeResult << 8);
  59. #else
  60. /*MM* } */
  61.     ret = waitpid((int)pid, statPtr, options);
  62. #endif /*MM*/
  63. #ifdef DEBUG
  64.     printf(", returns %d (*statPtr %x) %s %d\n", ret, *statPtr,
  65.            WIFEXITED(*statPtr) ? "WIFEXITED" :
  66.            (WIFSIGNALED(*statPtr) ? "WIFSIGNALED" :
  67.             (WIFSTOPPED(*statPtr) ? "WIFSTOPPED" : "unknown")),
  68.            WIFEXITED(*statPtr) ? WEXITSTATUS(*statPtr) :
  69.            (WIFSIGNALED(*statPtr) ? WTERMSIG(*statPtr) :
  70.             (WIFSTOPPED(*statPtr) ? WSTOPSIG(*statPtr) : 0)));
  71. #endif
  72.     return ret;
  73. }
  74.