File: waitnb.c

package info (click to toggle)
inn 1%3A1.7.2q-52
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,256 kB
  • sloc: ansic: 37,984; perl: 11,945; sh: 3,968; makefile: 2,009; awk: 1,567; yacc: 686; tcl: 85; csh: 70
file content (41 lines) | stat: -rw-r--r-- 801 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*  $Revision: 1.4 $
**
*/
#include <stdio.h>
#include <sys/types.h>
#include "configdata.h"
#include "clibrary.h"
#include <sys/wait.h>


#if	defined(DO_USE_UNION_WAIT)
typedef union wait	WAITER;
#if	defined(WEXITSTATUS)
#define WAITVAL(x)	(WEXITSTATUS(x))
#else
#define WAITVAL(x)	((x).w_retcode)
#endif	/* defined(WEXITSTATUS) */
#else
typedef int		WAITER;
#define WAITVAL(x)	(((x) >> 8) & 0xFF)
#endif	/* defined(DO_USE_UNION_WAIT) */

PID_T
waitnb(statusp)
    int		*statusp;
{
    WAITER	w;
    PID_T	pid;

#if	defined(DO_HAVE_WAITPID)
    pid = waitpid(-1, &w, WNOHANG);
#endif	/* defined(DO_HAVE_WAITPID) */

#if	defined(DONT_HAVE_WAITPID)
    pid = wait3(&w, WNOHANG, (struct rusage *)NULL);
#endif	/* defined(DONT_HAVE_WAITPID) */

    if (pid > 0)
	*statusp = WAITVAL(w);
    return pid;
}