/****** rsbx.lib/ChildStatus() ***********************************************
*
*   NAME
*	ChildStatus -- Check completion status of child process.
*
*   SYNOPSIS
*	completion = ChildStatus(child, status)
*
*	struct ChildNode *ChildStatus(struct ChildNode *, long *);
*
*   FUNCTION
*	Checks if a child process has completed and sets status to the return
*	    code from the child process if it has.
*
*   INPUTS
*	child         - Child process identifier returned from LaunchChildX();
*	status        - Pointer to a long to place the return code from the
*	                child process in.
*
*   RESULT
*	completion    - Child process identifier if child is a child process
*	                of this process and has completed. If child is a child
*	                process of this process and has not completed, then
*			completion is 0 and status is set to 0. If child is
*	                not a child procewss of this process, then completion
*	                is 0 and status will be non-zero.
*
*   NOTES
*
*   SEE ALSO
*	CreateFamily(), EmptyMorgue(), LaunchChildl(), LaunchChildv(),
*	OrphanChild(), OrphanChildren(), WaitChild().
*
*   BUGS
*	None known.
*
******************************************************************************
*
*/

#include <rsbx/childtasking.h>

struct ChildNode *ChildStatus(struct ChildNode *child, long *status)
	{
	struct ChildNode *node;

	EmptyMorgue();

	for (node = (struct ChildNode *)_Children->ChildList.mlh_Head;
		node->node.mln_Succ;
		node = (struct ChildNode *)node->node.mln_Succ)
		{
		if (node == child)
			{
			if (!child->notice.noticeptr)
				{
				*status = child->notice.ret;
				return child;
				}
			else
				{
				*status = 0;
				return 0;
				}
			}
		}

	*status = -1;
	return 0;
	}
