Debian Codegraph @

share/libc/fcntl.h

raw
1 /**************************************************************************/
2 /* */
3 /* This file is part of Frama-C. */
4 /* */
5 /* Copyright (C) 2007-2022 */
6 /* CEA (Commissariat à l'énergie atomique et aux énergies */
7 /* alternatives) */
8 /* */
9 /* you can redistribute it and/or modify it under the terms of the GNU */
10 /* Lesser General Public License as published by the Free Software */
11 /* Foundation, version 2.1. */
12 /* */
13 /* It is distributed in the hope that it will be useful, */
14 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
15 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
16 /* GNU Lesser General Public License for more details. */
17 /* */
18 /* See the GNU Lesser General Public License version 2.1 */
19 /* for more details (enclosed in the file licenses/LGPLv2.1). */
20 /* */
21 /**************************************************************************/
22
23 #ifndef __FC_FCNTL
24 #define __FC_FCNTL
25 #include "features.h"
26 __PUSH_FC_STDLIB
27
28 #include "__fc_define_off_t.h"
29 #include "__fc_define_pid_t.h"
30 #include "__fc_define_mode_t.h"
31 #include "__fc_define_max_open_files.h"
32 #include "__fc_string_axiomatic.h"
33
34 // The values for the constants below are based on an x86 Linux,
35 // declared in the order given by POSIX.1-2008.
36 // Macros which are not defined in such Linux are commented out.
37 #define F_DUPFD 0
38 #define F_DUPFD_CLOEXEC 0x406
39 #define F_GETFD 1
40 #define F_SETFD 2
41 #define F_GETFL 3
42 #define F_SETFL 4
43 #define F_GETLK 5
44 #define F_SETLK 6
45 #define F_SETLKW 7
46 #define F_GETOWN 9
47 #define F_SETOWN 8
48
49 #define FD_CLOEXEC 1
50
51 #define F_RDLCK 0
52 #define F_UNLCK 2
53 #define F_WRLCK 1
54
55 #include "__fc_define_seek_macros.h"
56
57 #define O_CLOEXEC 0x80000
58 #define O_CREAT 0x40
59 #define O_DIRECTORY 0x10000
60 #define O_EXCL 0x80
61 #define O_NOCTTY 0x100
62 #define O_NOFOLLOW 0x20000
63 #define O_TRUNC 0x200
64 //#define O_TTY_INIT
65
66 // Non-POSIX
67 #define O_DIRECT 0x4000
68
69 #define O_APPEND 0x400
70 #define O_DSYNC 0x1000
71 #define O_NONBLOCK 0x800
72 #define O_RSYNC 0x101000
73 #define O_SYNC 0x101000
74
75 #define O_ACCMODE 3
76
77 //#define O_EXEC
78 #define O_RDONLY 0
79 #define O_RDWR 2
80 //#define O_SEARCH
81 #define O_WRONLY 1
82
83 #define AT_FDCWD -100
84
85 #define AT_EACCESS 0x200
86
87 #define AT_SYMLINK_NOFOLLOW 0x100
88
89 #define AT_SYMLINK_FOLLOW 0x400
90
91 #define AT_REMOVEDIR 0x200
92
93 #define POSIX_FADV_DONTNEED 4
94 #define POSIX_FADV_NOREUSE 5
95 #define POSIX_FADV_NORMAL 0
96 #define POSIX_FADV_RANDOM 1
97 #define POSIX_FADV_SEQUENTIAL 2
98 #define POSIX_FADV_WILLNEED 3
99
100 // Non-POSIX, but used in some code
101 #define O_BINARY 0
102 #define O_TEXT 0
103
104 __BEGIN_DECLS
105
106 struct flock
107 {
108 short int l_type; /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK. */
109 short int l_whence; /* Where `l_start' is relative to (like `lseek'). */
110 off_t l_start; /* Offset where the lock begins. */
111 off_t l_len; /* Size of the locked area; zero means until EOF. */
112 pid_t l_pid; /* Process holding the lock. */
113 };
114
115 /*@
116 requires valid_filename: valid_read_string(filename);
117 assigns \result \from indirect:filename[0..], indirect:mode;
118 */
119 extern int creat(const char *filename, mode_t mode);
120
121 /*@ assigns \result \from fd, cmd ; */
122 extern int fcntl(int fd, int cmd, ...);
123
124 /*@
125 requires valid_filename: valid_read_string(filename);
126 assigns \result \from indirect:filename[0..], indirect:flags;
127 ensures valid_fd_or_error: \result == -1 || 0 <= \result < __FC_MAX_OPEN_FILES;
128 */
129 extern int open(const char *filename, int flags, ...);
130
131 /*@
132 requires valid_filename: valid_read_string(filename);
133 assigns \result \from indirect:dirfd, indirect:filename[0..], indirect:flags;
134 ensures valid_fd_or_error: \result == -1 || 0 <= \result < __FC_MAX_OPEN_FILES;
135 */
136 extern int openat(int dirfd, const char *filename, int flags, ...);
137
138 /* The following functions are "fixed-argument" versions of open/fcntl. They
139 are used when the translation of variadic function to fixed-adic is
140 enabled */
141
142 /*@ requires cmd_has_void_arg: cmd == F_GETFD || cmd == F_GETFL ||
143 cmd == F_GETOWN;
144 assigns \result \from fd, cmd ; */
145 extern int __va_fcntl_void(int fd, int cmd);
146
147 /*@ requires cmd_has_int_arg: cmd == F_DUPFD || cmd == F_DUPFD_CLOEXEC ||
148 cmd == F_SETFL || cmd == F_SETOWN ||
149 cmd == F_SETFD;
150 assigns \result \from fd, cmd, arg ;*/
151 extern int __va_fcntl_int(int fd, int cmd, int arg);
152
153 /*@ requires cmd_as_flock_arg: cmd == F_GETLK || cmd == F_SETLK ||
154 cmd == F_SETLKW ;
155 requires valid_arg: \valid(arg) ;
156 assigns \result, *arg \from fd, cmd, *arg ; */
157 extern int __va_fcntl_flock(int fd, int cmd, struct flock *arg);
158
159 /*@
160 requires valid_filename: valid_read_string(filename);
161 requires flag_not_CREAT: !(flags & O_CREAT) ;
162 assigns \result \from indirect:filename[0..], indirect:flags;
163 ensures valid_fd_or_error: \result == -1 || 0 <= \result < __FC_MAX_OPEN_FILES;
164 */
165 extern int __va_open_void(const char *filename, int flags);
166
167 /*@
168 requires valid_filename: valid_read_string(filename);
169 assigns \result \from indirect:filename[0..], indirect:flags,
170 indirect:mode;
171 ensures valid_fd_or_error: \result == -1 || 0 <= \result < __FC_MAX_OPEN_FILES;
172 */
173 extern int __va_open_mode_t(const char *filename, int flags, mode_t mode);
174
175 /*@
176 requires valid_filename: valid_read_string(filename);
177 requires flag_not_CREAT: !(flags & O_CREAT);
178 assigns \result \from indirect:dirfd, indirect:filename[0..],
179 indirect:flags;
180 ensures valid_fd_or_error: \result == -1 || 0 <= \result < __FC_MAX_OPEN_FILES;
181 */
182 extern int __va_openat_void(int dirfd, const char *filename, int flags);
183
184 /*@
185 requires valid_filename: valid_read_string(filename);
186 assigns \result \from indirect:dirfd, indirect:filename[0..], indirect:flags,
187 indirect:mode;
188 ensures valid_fd_or_error: \result == -1 || 0 <= \result < __FC_MAX_OPEN_FILES;
189 */
190 extern int __va_openat_mode_t(int dirfd, const char *filename, int flags, mode_t mode);
191
192 // The constants below are not in POSIX-1.2008, but are kept for compatibility
193
194 #define O_NDELAY O_NONBLOCK
195 #define O_FSYNC O_SYNC
196 #define O_ASYNC 0x2000
197
198 /* For old implementation of bsd flock(). */
199 #define F_EXLCK 4
200 #define F_SHLCK 8
201
202 __END_DECLS
203
204 __POP_FC_STDLIB
205 #endif