/* This file is part of Lcrzo.
*/

int lcrzo_process_other_wait_end(lcrzo_process *pprocess, 
                                 lcrzo_time *pmaxwaitingtime,
                                 lcrzo_bool *phasended,
                                 int *preturnvalue)
{ lcrzo_wait waitend;
  lcrzo_bool mayread;

  /* parameter verification */
  if (pprocess==NULL) return(LCRZO_ERR_PANULLPTR);

  /* check for immediate exit */
  if (pprocess->hasended)
  { mayread=LCRZO_TRUE;
  }
  else
  { /* wait */
    lcrzo_er(lcrzo_wait_init_process_end(pprocess, &waitend));
    lcrzo_er(lcrzo_wait_wait1(&waitend, pmaxwaitingtime, &mayread));
    lcrzo_er(lcrzo_wait_close(&waitend));
  }

  /* set output values */
  if (phasended!=NULL) *phasended=mayread;
  if (mayread)
  { 
#if defined LCRZODEF_SYSTEM_Unix
    lcrzo_er(lcrzo_priv_childprocesses_del(pprocess->processid));
    if (preturnvalue!=NULL)
    { *preturnvalue=(*pprocess->punixreturn_uint82int)(pprocess->returnedvalue);
    }
#elif defined LCRZODEF_SYSTEM_Windows
    if (preturnvalue!=NULL)
    { *preturnvalue=pprocess->returnedvalue;
    }
#else
 #error "Unknown value for LCRZODEF_SYSTEM"
#endif
  }

  return(LCRZO_ERR_OK);
}

