1 /* @(#)fcntl.h 1.21 18/07/15 Copyright 1996-2018 J. Schilling */ 2 /* 3 * Generic header for users of open(), creat() and chmod() 4 * 5 * Copyright (c) 1996-2018 J. Schilling 6 */ 7 /* 8 * The contents of this file are subject to the terms of the 9 * Common Development and Distribution License, Version 1.0 only 10 * (the "License"). You may not use this file except in compliance 11 * with the License. 12 * 13 * See the file CDDL.Schily.txt in this distribution for details. 14 * A copy of the CDDL is also available via the Internet at 15 * http://www.opensource.org/licenses/cddl1.txt 16 * 17 * When distributing Covered Code, include this CDDL HEADER in each 18 * file and include the License file CDDL.Schily.txt from this distribution. 19 */ 20 21 #ifndef _SCHILY_FCNTL_H 22 #define _SCHILY_FCNTL_H 23 24 #ifndef _SCHILY_MCONFIG_H 25 #include <schily/mconfig.h> 26 #endif 27 28 #ifndef _SCHILY_TYPES_H 29 #include <schily/types.h> /* Needed for fcntl.h */ 30 #endif 31 32 #ifndef _SCHILY_STAT_H 33 #include <schily/stat.h> /* For 3rd arg of open() and chmod() */ 34 #endif 35 36 #ifdef HAVE_SYS_FILE_H 37 /* 38 * Historical systems with flock() only need sys/file.h 39 */ 40 # ifndef _INCL_SYS_FILE_H 41 # include <sys/file.h> 42 # define _INCL_SYS_FILE_H 43 # endif 44 #endif 45 #ifdef HAVE_FCNTL_H 46 # ifndef _INCL_FCNTL_H 47 # include <fcntl.h> 48 # define _INCL_FCNTL_H 49 #endif 50 #endif 51 52 /* 53 * Do not define more than O_RDONLY / O_WRONLY / O_RDWR / O_BINARY 54 * The values may differ. 55 * 56 * O_BINARY is defined here to allow all applications to compile on a non DOS 57 * environment without repeating this definition. 58 * O_SEARCH, O_DIRECTORY and NOFOLLOW are defined here to allow to compile on 59 * older platforms. 60 * open(name, O_SEARCH) is like UNOS open(name, "") (open neither for read nor 61 * for write). This allows to call fstat() and to get an fd for openat(fd, ...) 62 */ 63 #ifndef O_RDONLY 64 # define O_RDONLY 0 65 #endif 66 #ifndef O_WRONLY 67 # define O_WRONLY 1 68 #endif 69 #ifndef O_RDWR 70 # define O_RDWR 2 71 #endif 72 #ifndef O_BINARY /* Only present on DOS or similar */ 73 # define O_BINARY 0 74 #endif 75 #ifndef O_NDELAY /* This is undefined on BeOS :-( */ 76 # define O_NDELAY 0 77 #endif 78 #ifndef O_EXEC /* Open for exec only (non-directory) */ 79 # define O_EXEC O_RDONLY 80 #endif 81 #ifndef O_SEARCH /* Open for search only. */ 82 /* 83 * O_SEARCH is in POSIX.1-2008, but Linux added O_PATH in 2011 84 * so Linux people do not seem to read the standard. 85 */ 86 #ifdef O_PATH 87 # define O_SEARCH O_PATH /* Linux O_PATH is similar */ 88 #else 89 # define O_SEARCH O_RDONLY 90 #endif 91 #endif 92 #ifndef O_DIRECTORY /* Fail if not a directory */ 93 # define O_DIRECTORY 0 94 #endif 95 #ifndef O_NOFOLLOW /* Fail if a symlink */ 96 # define O_NOFOLLOW 0 97 #endif 98 99 #ifndef O_ACCMODE 100 #define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR|O_EXEC|O_SEARCH) 101 #endif 102 103 #ifdef O_NOATIME /* Allow #ifdef O_NOATIME */ 104 #define _O_NOATIME O_NOATIME 105 #else 106 #define _O_NOATIME 0 107 #endif 108 109 #ifndef FD_CLOEXEC 110 #define FD_CLOEXEC 1 /* close on exec flag */ 111 #endif 112 113 /* 114 * The following definitions are used for emulating the *at() functions. 115 * We use higher numbers for our definitions, to allow to add emulations 116 * for missing functions without causing a clash with system definitions. 117 */ 118 #ifndef HAVE_OPENAT 119 #ifndef AT_FDCWD 120 #define AT_FDCWD 0xffd19553 /* *at() to working dir */ 121 #endif 122 #endif 123 #ifndef HAVE_FSTATAT 124 #ifndef AT_SYMLINK_NOFOLLOW 125 #define AT_SYMLINK_NOFOLLOW 0x10000 /* emulate lstat() */ 126 #endif 127 #endif 128 #ifndef HAVE_UNLINKAT 129 #ifndef AT_REMOVEDIR 130 #define AT_REMOVEDIR 0x20000 /* emulate rmdir() */ 131 #endif 132 #endif 133 #ifndef HAVE_FACCESSAT 134 #ifndef AT_EACCESS 135 #define AT_EACCESS 0x40000 /* EUID access() */ 136 #endif 137 #endif 138 #ifndef HAVE_LINKAT 139 #ifndef AT_SYMLINK_FOLLOW 140 #define AT_SYMLINK_FOLLOW 0x80000 /* follow symlinks before link() */ 141 #endif 142 #endif 143 144 #endif /* _SCHILY_FCNTL_H */ 145