/* This file is part of Lcrzo.
*/

int lcrzo_process_current_exit(int returnvalue)
{ 
#if defined LCRZODEF_SYSTEM_Unix
  lcrzo_priv_globalvars *ptr;
  lcrzo_uint8 (*int2uint8)(int ret);
  int ret;
  
  lcrzo_priv_childprocesses_killall();
  ret=lcrzo_priv_globalvars_ptr_get(&ptr);
  if (ret!=LCRZO_ERR_OK) _exit(returnvalue);

  /* save function before closing */
  int2uint8=ptr->pprocess_int2uint8;

#if LCRZO_PRIV_DATA_ALLOC_DEBUG==2
  /* we can call lcrzo_priv_globalvars_close() everytime, but it is not useful
     because the process exits now */
  lcrzo_priv_globalvars_close();
  /* debug memory leaks */
  checkmemory_report();
#endif

  /* to be sure every message is displayed */
  fflush(stdout);
  fflush(stderr);
  _exit((*int2uint8)(returnvalue));

#elif defined LCRZODEF_SYSTEM_Windows
  lcrzo_close_forthreadonly();
  /* to be sure every message is displayed */
  fflush(stdout);
  fflush(stderr);
 #if 0
  ExitThread(returnvalue);
 #else
  _endthreadex(returnvalue);
 #endif

#else
 #error "Unknown value for LCRZODEF_SYSTEM"
#endif
  return(lcrzo_ierp("lcrzo_process_current_exit"));
}


