// sys/wait.h -- GNO/ME process-wait status decoding.
//
// GNO's wait status is a single 16-bit int (sizeof(int)==2 on this target), the
// BSD "union wait" word (see tools/gno/src-repo/include/sys/wait.h):
//   bits 0-6   termination signal (0 => normal exit)
//   bit  7     core-dump flag (always 0 under GNO)
//   bits 8-15  exit code (valid when the termination signal is 0)
// So a normal exit(N) yields status (N << 8); WEXITSTATUS shifts it back down.
#ifndef _SYS_WAIT_H
#define _SYS_WAIT_H

#define WIFEXITED(s)    (((s) & 0x7F) == 0)
#define WEXITSTATUS(s)  (((s) >> 8) & 0xFF)
#define WIFSIGNALED(s)  (((s) & 0x7F) != 0 && ((s) & 0x7F) != 0x7F)
#define WTERMSIG(s)     ((s) & 0x7F)
#define WIFSTOPPED(s)   (((s) & 0x7F) == 0x7F)
#define WSTOPSIG(s)     (((s) >> 8) & 0xFF)
#define WCOREDUMP(s)    0

// Option bits for waitpid's third argument.  WNOHANG cannot be honored (the GNO
// kernel wait() blocks); waitpid rejects it.
#define WNOHANG         1
#define WUNTRACED       2

int wait(int *status);
int waitpid(int pid, int *status, int options);

#endif
