(root)/
grep-3.11/
gnulib-tests/
test-fcntl-h.c
       1  /* Test of <fcntl.h> substitute.
       2     Copyright (C) 2007, 2009-2023 Free Software Foundation, Inc.
       3  
       4     This program is free software: you can redistribute it and/or modify
       5     it under the terms of the GNU General Public License as published by
       6     the Free Software Foundation, either version 3 of the License, or
       7     (at your option) any later version.
       8  
       9     This program is distributed in the hope that it will be useful,
      10     but WITHOUT ANY WARRANTY; without even the implied warranty of
      11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12     GNU General Public License for more details.
      13  
      14     You should have received a copy of the GNU General Public License
      15     along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
      16  
      17  /* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
      18  
      19  #include <config.h>
      20  
      21  #include <fcntl.h>
      22  
      23  /* Check that the various O_* macros are defined.  */
      24  int o = (O_DIRECT | O_DIRECTORY | O_DSYNC | O_IGNORE_CTTY | O_NDELAY | O_NOATIME
      25           | O_NONBLOCK | O_NOCTTY | O_NOFOLLOW | O_NOLINK | O_NOLINKS | O_NOTRANS
      26           | O_RSYNC | O_SYNC | O_TTY_INIT | O_BINARY | O_TEXT);
      27  
      28  /* Check that the various SEEK_* macros are defined.  */
      29  int sk[] = { SEEK_CUR, SEEK_END, SEEK_SET };
      30  
      31  /* Check that the FD_* macros are defined.  */
      32  int i = FD_CLOEXEC;
      33  
      34  /* Check that the types are all defined.  */
      35  pid_t t1;
      36  off_t t2;
      37  mode_t t3;
      38  
      39  int
      40  main (void)
      41  {
      42    /* Ensure no overlap in SEEK_*. */
      43    switch (0)
      44      {
      45      case SEEK_CUR:
      46      case SEEK_END:
      47      case SEEK_SET:
      48        ;
      49      }
      50  
      51    /* Ensure no dangerous overlap in non-zero gnulib-defined replacements.  */
      52    switch (O_RDONLY)
      53      {
      54        /* Access modes */
      55      case O_RDONLY:
      56      case O_WRONLY:
      57      case O_RDWR:
      58  #if O_EXEC && O_EXEC != O_RDONLY
      59      case O_EXEC:
      60  #endif
      61  #if O_SEARCH && O_EXEC != O_SEARCH && O_SEARCH != O_RDONLY
      62      case O_SEARCH:
      63  #endif
      64        i = ! (~O_ACCMODE & (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH));
      65        break;
      66  
      67        /* Everyone should have these */
      68      case O_CREAT:
      69      case O_EXCL:
      70      case O_TRUNC:
      71      case O_APPEND:
      72        break;
      73  
      74        /* These might be 0 or O_RDONLY, only test non-zero versions.  */
      75  #if O_CLOEXEC
      76      case O_CLOEXEC:
      77  #endif
      78  #if O_DIRECT
      79      case O_DIRECT:
      80  #endif
      81  #if O_DIRECTORY
      82      case O_DIRECTORY:
      83  #endif
      84  #if O_DSYNC
      85      case O_DSYNC:
      86  #endif
      87  #if O_IGNORE_CTTY
      88      case O_IGNORE_CTTY:
      89  #endif
      90  #if O_NOATIME
      91      case O_NOATIME:
      92  #endif
      93  #if O_NONBLOCK
      94      case O_NONBLOCK:
      95  #endif
      96  #if O_NOCTTY
      97      case O_NOCTTY:
      98  #endif
      99  #if O_NOFOLLOW
     100      case O_NOFOLLOW:
     101  #endif
     102  #if O_NOLINK
     103      case O_NOLINK:
     104  #endif
     105  #if O_NOLINKS
     106      case O_NOLINKS:
     107  #endif
     108  #if O_NOTRANS
     109      case O_NOTRANS:
     110  #endif
     111  #if O_RSYNC && O_RSYNC != O_DSYNC
     112      case O_RSYNC:
     113  #endif
     114  #if O_SYNC && O_SYNC != O_DSYNC && O_SYNC != O_RSYNC
     115      case O_SYNC:
     116  #endif
     117  #if O_TTY_INIT
     118      case O_TTY_INIT:
     119  #endif
     120  #if O_BINARY
     121      case O_BINARY:
     122  #endif
     123  #if O_TEXT
     124      case O_TEXT:
     125  #endif
     126        ;
     127      }
     128  
     129    return !i;
     130  }