Blame gnulib-tests/test-sys_wait.h

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