| 1 |
/* Test of <fcntl.h> substitute. |
| 2 |
Copyright (C) 2007, 2009-2025 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 <[email protected]>, 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 |
off64_t t4; |
| 39 |
|
| 40 |
int |
| 41 |
main (void) |
| 42 |
{ |
| 43 |
/* Ensure no overlap in SEEK_*. */ |
| 44 |
switch (0) |
| 45 |
{ |
| 46 |
case SEEK_CUR: |
| 47 |
case SEEK_END: |
| 48 |
case SEEK_SET: |
| 49 |
; |
| 50 |
} |
| 51 |
|
| 52 |
/* Ensure no dangerous overlap in non-zero gnulib-defined replacements. */ |
| 53 |
switch (O_RDONLY) |
| 54 |
{ |
| 55 |
/* Access modes */ |
| 56 |
case O_RDONLY: |
| 57 |
case O_WRONLY: |
| 58 |
case O_RDWR: |
| 59 |
#if O_EXEC && O_EXEC != O_RDONLY |
| 60 |
case O_EXEC: |
| 61 |
#endif |
| 62 |
#if O_SEARCH && O_EXEC != O_SEARCH && O_SEARCH != O_RDONLY |
| 63 |
case O_SEARCH: |
| 64 |
#endif |
| 65 |
i = ! (~O_ACCMODE & (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH)); |
| 66 |
break; |
| 67 |
|
| 68 |
/* Everyone should have these */ |
| 69 |
case O_CREAT: |
| 70 |
case O_EXCL: |
| 71 |
case O_TRUNC: |
| 72 |
case O_APPEND: |
| 73 |
break; |
| 74 |
|
| 75 |
/* These might be 0 or O_RDONLY, only test non-zero versions. */ |
| 76 |
#if O_CLOEXEC |
| 77 |
case O_CLOEXEC: |
| 78 |
#endif |
| 79 |
#if O_DIRECT |
| 80 |
case O_DIRECT: |
| 81 |
#endif |
| 82 |
#if O_DIRECTORY |
| 83 |
case O_DIRECTORY: |
| 84 |
#endif |
| 85 |
#if O_DSYNC |
| 86 |
case O_DSYNC: |
| 87 |
#endif |
| 88 |
#if O_IGNORE_CTTY |
| 89 |
case O_IGNORE_CTTY: |
| 90 |
#endif |
| 91 |
#if O_NOATIME |
| 92 |
case O_NOATIME: |
| 93 |
#endif |
| 94 |
#if O_NONBLOCK |
| 95 |
case O_NONBLOCK: |
| 96 |
#endif |
| 97 |
#if O_NOCTTY |
| 98 |
case O_NOCTTY: |
| 99 |
#endif |
| 100 |
#if O_NOFOLLOW |
| 101 |
case O_NOFOLLOW: |
| 102 |
#endif |
| 103 |
#if O_NOLINK |
| 104 |
case O_NOLINK: |
| 105 |
#endif |
| 106 |
#if O_NOLINKS |
| 107 |
case O_NOLINKS: |
| 108 |
#endif |
| 109 |
#if O_NOTRANS |
| 110 |
case O_NOTRANS: |
| 111 |
#endif |
| 112 |
#if O_RSYNC && O_RSYNC != O_DSYNC |
| 113 |
case O_RSYNC: |
| 114 |
#endif |
| 115 |
#if O_SYNC && O_SYNC != O_DSYNC && O_SYNC != O_RSYNC |
| 116 |
case O_SYNC: |
| 117 |
#endif |
| 118 |
#if O_TTY_INIT |
| 119 |
case O_TTY_INIT: |
| 120 |
#endif |
| 121 |
#if O_BINARY |
| 122 |
case O_BINARY: |
| 123 |
#endif |
| 124 |
#if O_TEXT |
| 125 |
case O_TEXT: |
| 126 |
#endif |
| 127 |
; |
| 128 |
} |
| 129 |
|
| 130 |
return !i; |
| 131 |
} |