Blame gnulib-tests/test-sys_wait.h

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