Blame gl/tests/test-sys_wait.h

Packit aea12f
/* Test of macros shared between <sys/wait.h> and <stdlib.h>.
Packit Service 991b93
   Copyright (C) 2010-2020 Free Software Foundation, Inc.
Packit aea12f
Packit aea12f
   This program is free software: you can redistribute it and/or modify
Packit aea12f
   it under the terms of the GNU General Public License as published by
Packit aea12f
   the Free Software Foundation; either version 3 of the License, or
Packit aea12f
   (at your option) any later version.
Packit aea12f
Packit aea12f
   This program is distributed in the hope that it will be useful,
Packit aea12f
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit aea12f
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit aea12f
   GNU General Public License for more details.
Packit aea12f
Packit aea12f
   You should have received a copy of the GNU General Public License
Packit aea12f
   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
Packit aea12f
Packit aea12f
/* Written by Eric Blake <ebb9@byu.net>, 2010.  */
Packit aea12f
Packit aea12f
static int
Packit aea12f
test_sys_wait_macros (void)
Packit aea12f
{
Packit aea12f
  /* Check subset of <sys/wait.h> macros that must be visible here.
Packit aea12f
     Note that some of these macros are only portable when operating
Packit aea12f
     on an lvalue.  */
Packit aea12f
  int i;
Packit aea12f
  for (i = 0; i < 0x8000; i = (i ? i << 1 : 1))
Packit aea12f
    {
Packit aea12f
      /* POSIX requires that for all valid process statuses, that
Packit aea12f
         exactly one of these three macros is true.  But not all
Packit aea12f
         possible 16-bit values map to valid process status.
Packit aea12f
         Traditionally, 8 of the bits are for WIFEXITED, 7 of the bits
Packit aea12f
         to tell between WIFSIGNALED and WIFSTOPPED, and either 0x80
Packit aea12f
         or 0x8000 to flag that core was also dumped.  Since we don't
Packit aea12f
         know which byte is WIFEXITED, we skip the both possible bits
Packit aea12f
         that can signal core dump.  */
Packit aea12f
      if (i == 0x80)
Packit aea12f
        continue;
Packit aea12f
      if (!!WIFSIGNALED (i) + !!WIFEXITED (i) + !!WIFSTOPPED (i) != 1)
Packit aea12f
        return 1;
Packit aea12f
    }
Packit aea12f
  i = WEXITSTATUS (i) + WSTOPSIG (i) + WTERMSIG (i);
Packit aea12f
Packit aea12f
  switch (i)
Packit aea12f
    {
Packit aea12f
#if 0
Packit aea12f
  /* Gnulib doesn't guarantee these, yet.  */
Packit aea12f
    case WNOHANG:
Packit aea12f
    case WUNTRACED:
Packit aea12f
#endif
Packit aea12f
      break;
Packit aea12f
    }
Packit aea12f
  return 0;
Packit aea12f
}