Blame gnulib-tests/test-fcntl-h.c

Packit 709fb3
/* Test of <fcntl.h> substitute.
Packit 709fb3
   Copyright (C) 2007, 2009-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 Bruno Haible <bruno@clisp.org>, 2007.  */
Packit 709fb3
Packit 709fb3
#include <config.h>
Packit 709fb3
Packit 709fb3
#include <fcntl.h>
Packit 709fb3
Packit 709fb3
/* Check that the various O_* macros are defined.  */
Packit 709fb3
int o = (O_DIRECT | O_DIRECTORY | O_DSYNC | O_IGNORE_CTTY | O_NDELAY | O_NOATIME
Packit 709fb3
	 | O_NONBLOCK | O_NOCTTY | O_NOFOLLOW | O_NOLINK | O_NOLINKS | O_NOTRANS
Packit 709fb3
	 | O_RSYNC | O_SYNC | O_TTY_INIT | O_BINARY | O_TEXT);
Packit 709fb3
Packit 709fb3
/* Check that the various SEEK_* macros are defined.  */
Packit 709fb3
int sk[] = { SEEK_CUR, SEEK_END, SEEK_SET };
Packit 709fb3
Packit 709fb3
/* Check that the FD_* macros are defined.  */
Packit 709fb3
int i = FD_CLOEXEC;
Packit 709fb3
Packit 709fb3
/* Check that the types are all defined.  */
Packit 709fb3
pid_t t1;
Packit 709fb3
off_t t2;
Packit 709fb3
mode_t t3;
Packit 709fb3
Packit 709fb3
int
Packit 709fb3
main (void)
Packit 709fb3
{
Packit 709fb3
  /* Ensure no overlap in SEEK_*. */
Packit 709fb3
  switch (0)
Packit 709fb3
    {
Packit 709fb3
    case SEEK_CUR:
Packit 709fb3
    case SEEK_END:
Packit 709fb3
    case SEEK_SET:
Packit 709fb3
      ;
Packit 709fb3
    }
Packit 709fb3
Packit 709fb3
  /* Ensure no dangerous overlap in non-zero gnulib-defined replacements.  */
Packit 709fb3
  switch (O_RDONLY)
Packit 709fb3
    {
Packit 709fb3
      /* Access modes */
Packit 709fb3
    case O_RDONLY:
Packit 709fb3
    case O_WRONLY:
Packit 709fb3
    case O_RDWR:
Packit 709fb3
#if O_EXEC && O_EXEC != O_RDONLY
Packit 709fb3
    case O_EXEC:
Packit 709fb3
#endif
Packit 709fb3
#if O_SEARCH && O_EXEC != O_SEARCH && O_SEARCH != O_RDONLY
Packit 709fb3
    case O_SEARCH:
Packit 709fb3
#endif
Packit 709fb3
      i = ! (~O_ACCMODE & (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH));
Packit 709fb3
      break;
Packit 709fb3
Packit 709fb3
      /* Everyone should have these */
Packit 709fb3
    case O_CREAT:
Packit 709fb3
    case O_EXCL:
Packit 709fb3
    case O_TRUNC:
Packit 709fb3
    case O_APPEND:
Packit 709fb3
      break;
Packit 709fb3
Packit 709fb3
      /* These might be 0 or O_RDONLY, only test non-zero versions.  */
Packit 709fb3
#if O_CLOEXEC
Packit 709fb3
    case O_CLOEXEC:
Packit 709fb3
#endif
Packit 709fb3
#if O_DIRECT
Packit 709fb3
    case O_DIRECT:
Packit 709fb3
#endif
Packit 709fb3
#if O_DIRECTORY
Packit 709fb3
    case O_DIRECTORY:
Packit 709fb3
#endif
Packit 709fb3
#if O_DSYNC
Packit 709fb3
    case O_DSYNC:
Packit 709fb3
#endif
Packit 709fb3
#if O_IGNORE_CTTY
Packit 709fb3
    case O_IGNORE_CTTY:
Packit 709fb3
#endif
Packit 709fb3
#if O_NOATIME
Packit 709fb3
    case O_NOATIME:
Packit 709fb3
#endif
Packit 709fb3
#if O_NONBLOCK
Packit 709fb3
    case O_NONBLOCK:
Packit 709fb3
#endif
Packit 709fb3
#if O_NOCTTY
Packit 709fb3
    case O_NOCTTY:
Packit 709fb3
#endif
Packit 709fb3
#if O_NOFOLLOW
Packit 709fb3
    case O_NOFOLLOW:
Packit 709fb3
#endif
Packit 709fb3
#if O_NOLINK
Packit 709fb3
    case O_NOLINK:
Packit 709fb3
#endif
Packit 709fb3
#if O_NOLINKS
Packit 709fb3
    case O_NOLINKS:
Packit 709fb3
#endif
Packit 709fb3
#if O_NOTRANS
Packit 709fb3
    case O_NOTRANS:
Packit 709fb3
#endif
Packit 709fb3
#if O_RSYNC && O_RSYNC != O_DSYNC
Packit 709fb3
    case O_RSYNC:
Packit 709fb3
#endif
Packit 709fb3
#if O_SYNC && O_SYNC != O_DSYNC && O_SYNC != O_RSYNC
Packit 709fb3
    case O_SYNC:
Packit 709fb3
#endif
Packit 709fb3
#if O_TTY_INIT
Packit 709fb3
    case O_TTY_INIT:
Packit 709fb3
#endif
Packit 709fb3
#if O_BINARY
Packit 709fb3
    case O_BINARY:
Packit 709fb3
#endif
Packit 709fb3
#if O_TEXT
Packit 709fb3
    case O_TEXT:
Packit 709fb3
#endif
Packit 709fb3
      ;
Packit 709fb3
    }
Packit 709fb3
Packit 709fb3
  return !i;
Packit 709fb3
}