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

Packit Service fdd496
/* Test of <fcntl.h> substitute.
Packit Service fdd496
   Copyright (C) 2007, 2009-2017 Free Software Foundation, Inc.
Packit Service fdd496
Packit Service fdd496
   This program is free software: you can redistribute it and/or modify
Packit Service fdd496
   it under the terms of the GNU General Public License as published by
Packit Service fdd496
   the Free Software Foundation; either version 3 of the License, or
Packit Service fdd496
   (at your option) any later version.
Packit Service fdd496
Packit Service fdd496
   This program is distributed in the hope that it will be useful,
Packit Service fdd496
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service fdd496
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service fdd496
   GNU General Public License for more details.
Packit Service fdd496
Packit Service fdd496
   You should have received a copy of the GNU General Public License
Packit Service fdd496
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit Service fdd496
Packit Service fdd496
/* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
Packit Service fdd496
Packit Service fdd496
#include <config.h>
Packit Service fdd496
Packit Service fdd496
#include <fcntl.h>
Packit Service fdd496
Packit Service fdd496
/* Check that the various O_* macros are defined.  */
Packit Service fdd496
int o = (O_DIRECT | O_DIRECTORY | O_DSYNC | O_IGNORE_CTTY | O_NDELAY | O_NOATIME
Packit Service fdd496
	 | O_NONBLOCK | O_NOCTTY | O_NOFOLLOW | O_NOLINK | O_NOLINKS | O_NOTRANS
Packit Service fdd496
	 | O_RSYNC | O_SYNC | O_TTY_INIT | O_BINARY | O_TEXT);
Packit Service fdd496
Packit Service fdd496
/* Check that the various SEEK_* macros are defined.  */
Packit Service fdd496
int sk[] = { SEEK_CUR, SEEK_END, SEEK_SET };
Packit Service fdd496
Packit Service fdd496
/* Check that the FD_* macros are defined.  */
Packit Service fdd496
int i = FD_CLOEXEC;
Packit Service fdd496
Packit Service fdd496
/* Check that the types are all defined.  */
Packit Service fdd496
pid_t t1;
Packit Service fdd496
off_t t2;
Packit Service fdd496
mode_t t3;
Packit Service fdd496
Packit Service fdd496
int
Packit Service fdd496
main (void)
Packit Service fdd496
{
Packit Service fdd496
  /* Ensure no overlap in SEEK_*. */
Packit Service fdd496
  switch (0)
Packit Service fdd496
    {
Packit Service fdd496
    case SEEK_CUR:
Packit Service fdd496
    case SEEK_END:
Packit Service fdd496
    case SEEK_SET:
Packit Service fdd496
      ;
Packit Service fdd496
    }
Packit Service fdd496
Packit Service fdd496
  /* Ensure no dangerous overlap in non-zero gnulib-defined replacements.  */
Packit Service fdd496
  switch (O_RDONLY)
Packit Service fdd496
    {
Packit Service fdd496
      /* Access modes */
Packit Service fdd496
    case O_RDONLY:
Packit Service fdd496
    case O_WRONLY:
Packit Service fdd496
    case O_RDWR:
Packit Service fdd496
#if O_EXEC && O_EXEC != O_RDONLY
Packit Service fdd496
    case O_EXEC:
Packit Service fdd496
#endif
Packit Service fdd496
#if O_SEARCH && O_EXEC != O_SEARCH && O_SEARCH != O_RDONLY
Packit Service fdd496
    case O_SEARCH:
Packit Service fdd496
#endif
Packit Service fdd496
      i = ! (~O_ACCMODE & (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH));
Packit Service fdd496
      break;
Packit Service fdd496
Packit Service fdd496
      /* Everyone should have these */
Packit Service fdd496
    case O_CREAT:
Packit Service fdd496
    case O_EXCL:
Packit Service fdd496
    case O_TRUNC:
Packit Service fdd496
    case O_APPEND:
Packit Service fdd496
      break;
Packit Service fdd496
Packit Service fdd496
      /* These might be 0 or O_RDONLY, only test non-zero versions.  */
Packit Service fdd496
#if O_CLOEXEC
Packit Service fdd496
    case O_CLOEXEC:
Packit Service fdd496
#endif
Packit Service fdd496
#if O_DIRECT
Packit Service fdd496
    case O_DIRECT:
Packit Service fdd496
#endif
Packit Service fdd496
#if O_DIRECTORY
Packit Service fdd496
    case O_DIRECTORY:
Packit Service fdd496
#endif
Packit Service fdd496
#if O_DSYNC
Packit Service fdd496
    case O_DSYNC:
Packit Service fdd496
#endif
Packit Service fdd496
#if O_IGNORE_CTTY
Packit Service fdd496
    case O_IGNORE_CTTY:
Packit Service fdd496
#endif
Packit Service fdd496
#if O_NOATIME
Packit Service fdd496
    case O_NOATIME:
Packit Service fdd496
#endif
Packit Service fdd496
#if O_NONBLOCK
Packit Service fdd496
    case O_NONBLOCK:
Packit Service fdd496
#endif
Packit Service fdd496
#if O_NOCTTY
Packit Service fdd496
    case O_NOCTTY:
Packit Service fdd496
#endif
Packit Service fdd496
#if O_NOFOLLOW
Packit Service fdd496
    case O_NOFOLLOW:
Packit Service fdd496
#endif
Packit Service fdd496
#if O_NOLINK
Packit Service fdd496
    case O_NOLINK:
Packit Service fdd496
#endif
Packit Service fdd496
#if O_NOLINKS
Packit Service fdd496
    case O_NOLINKS:
Packit Service fdd496
#endif
Packit Service fdd496
#if O_NOTRANS
Packit Service fdd496
    case O_NOTRANS:
Packit Service fdd496
#endif
Packit Service fdd496
#if O_RSYNC && O_RSYNC != O_DSYNC
Packit Service fdd496
    case O_RSYNC:
Packit Service fdd496
#endif
Packit Service fdd496
#if O_SYNC && O_SYNC != O_DSYNC && O_SYNC != O_RSYNC
Packit Service fdd496
    case O_SYNC:
Packit Service fdd496
#endif
Packit Service fdd496
#if O_TTY_INIT
Packit Service fdd496
    case O_TTY_INIT:
Packit Service fdd496
#endif
Packit Service fdd496
#if O_BINARY
Packit Service fdd496
    case O_BINARY:
Packit Service fdd496
#endif
Packit Service fdd496
#if O_TEXT
Packit Service fdd496
    case O_TEXT:
Packit Service fdd496
#endif
Packit Service fdd496
      ;
Packit Service fdd496
    }
Packit Service fdd496
Packit Service fdd496
  return !i;
Packit Service fdd496
}