Debian Codegraph @

share/libc/sys/stat.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_SYS_STAT_H
24 #define __FC_SYS_STAT_H
25 #include "features.h"
26 __PUSH_FC_STDLIB
27 __BEGIN_DECLS
28
29 #include "../__fc_define_stat.h"
30 #include "../__fc_string_axiomatic.h"
31 #include "../errno.h"
32
33 /*@
34 // missing: assigns 'filesystem' \frompath, path[0..], mode;
35 requires valid_path: valid_read_string(path);
36 assigns \result, __fc_errno
37 \from indirect:path, indirect:path[0 .. strlen(path)],
38 indirect:mode; //missing: \from 'filesystem'
39 ensures errno_set: __fc_errno == \old(__fc_errno) ||
40 __fc_errno \in {EACCES, EINTR, EINVAL, ELOOP,
41 ENAMETOOLONG, ENOENT, ENOTDIR, EPERM,
42 EROFS};
43 ensures result_ok_or_error: \result == 0 || \result == -1;
44 */
45 extern int chmod(const char *path, mode_t mode);
46
47 /*@
48 // missing: assigns 'filesystem' \from fd, path, path[0..], mode, flag;
49 requires valid_path: valid_read_string(path);
50 assigns \result, __fc_errno
51 \from indirect:fd, indirect:path, indirect:path[0 .. strlen(path)],
52 indirect:mode, indirect:flag; //missing: \from 'filesystem'
53 ensures errno_set: __fc_errno == \old(__fc_errno) ||
54 __fc_errno \in {EACCES, EBADF, EINTR, EINVAL, ELOOP,
55 ENAMETOOLONG, ENOENT, ENOTDIR, EOPNOTSUPP,
56 EPERM, EROFS};
57 ensures result_ok_or_error: \result == 0 || \result == -1;
58 */
59 extern int fchmodat(int fd, const char *path, mode_t mode, int flag);
60
61 /*@
62 // missing: assigns 'filesystem' \from fildes, mode;
63 assigns \result, __fc_errno
64 \from indirect:fildes, indirect:mode; //missing: \from 'filesystem'
65 ensures errno_set: __fc_errno == \old(__fc_errno) ||
66 __fc_errno \in {EBADF, EINTR, EINVAL, EPERM, EROFS};
67 ensures result_ok_or_error: \result == 0 || \result == -1;
68 */
69 extern int fchmod(int fildes, mode_t mode);
70
71 /*@
72 //TODO: define proper initialization postcondition; it involves only a few
73 // specific fields, and only a few bits within those fields.
74 requires valid_buf: \valid(buf);
75 assigns \result, *buf, __fc_errno
76 \from indirect:fildes; //missing: \from 'filesystem'
77 ensures errno_set: __fc_errno == \old(__fc_errno) ||
78 __fc_errno \in {EBADF, EIO, EOVERFLOW};
79 ensures result_ok_or_error: \result == 0 || \result == -1;
80 */
81 extern int fstat(int fildes, struct stat *buf);
82
83 /*@
84 // missing: assigns 'filesystem' \from fd, path, path[0..], flag;
85 requires valid_path: valid_read_string(path);
86 requires valid_buf: \valid(buf);
87 assigns \result, *buf, __fc_errno
88 \from indirect:fd, indirect:path, indirect:path[0 .. strlen(path)],
89 indirect:flag; //missing: \from 'filesystem'
90 ensures errno_set: __fc_errno == \old(__fc_errno) ||
91 __fc_errno \in {EACCES, EBADF, EINVAL, EIO, ELOOP,
92 ENAMETOOLONG, ENOENT, ENOMEM, ENOTDIR,
93 EOVERFLOW};
94 ensures result_ok_or_error: \result == 0 || \result == -1;
95 */
96 extern int fstatat(int fd, const char *restrict path,
97 struct stat *restrict buf, int flag);
98
99 /*@ // missing: may assign to errno: EACCES, ELOOP, ENAMETOOLONG,
100 // ENOENT, ENOMEM, ENOTDIR, EOVERFLOW,
101 // EINVAL
102 // missing: assigns \result, *buf \from 'filesystem'
103 requires valid_path: valid_read_string(path);
104 requires valid_buf: \valid(buf);
105 assigns \result, *buf \from indirect:path, indirect:path[0..strlen(path)];
106 ensures result_ok_or_error: \result == 0 || \result == -1;
107 */
108 extern int lstat(const char *path, struct stat *buf);
109
110 /*@ // missing: may assign to errno: EACCES, EEXIST, ELOOP, EMLINK,
111 // ENAMETOOLONG, ENOENT, ENOSPC,
112 // ENOTDIR, EROFS
113 // missing: assigns \result \from 'filesystem'
114 requires valid_path: valid_read_string(path);
115 assigns \result \from indirect:path, indirect:path[0..strlen(path)],
116 indirect:mode;
117 ensures result_ok_or_error: \result == 0 || \result == -1;
118 */
119 extern int mkdir(const char *path, mode_t mode);
120
121 /*@ // missing: may assign to errno: EACCES, EEXIST, ELOOP, ENAMETOOLONG,
122 // ENOENT, ENOTDIR, ENOSPC, EROFS
123 // missing: assigns \result \from 'filesystem'
124 // missing: assigns 'filesystem' \from indirect:path,
125 // indirect:path[0..strlen(path)], mode;
126 requires valid_path: valid_read_string(path);
127 assigns \result \from indirect:path, indirect:path[0..strlen(path)],
128 indirect:mode;
129 ensures result_ok_or_error: \result == 0 || \result == -1;
130 */
131 extern int mkfifo(const char *path, mode_t mode);
132
133 /*@ // missing: may assign to errno: EACCES, EEXIST, EINVAL, EIO, ELOOP,
134 // ENAMETOOLONG, ENOENT, ENOTDIR, ENOSPC,
135 // EPERM, EROFS
136 // missing: assigns \result \from 'filesystem'
137 // missing: assigns 'filesystem' \from indirect:path,
138 // indirect:path[0..strlen(path)], mode, dev;
139 requires valid_path: valid_read_string(path);
140 assigns \result \from indirect:path, indirect:path[0..strlen(path)],
141 indirect:mode, indirect:dev;
142 ensures result_ok_or_error: \result == 0 || \result == -1;
143 */
144 extern int mknod(const char *path, mode_t mode, dev_t dev);
145
146 /*@ //missing: assigns \from 'filesystem'
147 requires valid_pathname: valid_read_string(pathname);
148 requires valid_buf: \valid(buf);
149 assigns \result, *buf \from pathname[0..strlen(pathname)];
150 ensures result_ok_or_error: \result == 0 || \result == -1;
151 ensures init_on_success:initialization:buf:
152 \result == 0 ==> \initialized(buf);
153 */
154 extern int stat(const char *pathname, struct stat *buf);
155
156 /*@ //missing: assigns 'process umask' \from cmask;
157 //missing: assigns \result \from 'old process umask'
158 assigns \result \from indirect:cmask;
159 */
160 extern mode_t umask(mode_t cmask);
161
162 #define S_TYPEISMQ(buf) ((buf)->st_mode - (buf)->st_mode)
163 #define S_TYPEISSEM(buf) ((buf)->st_mode - (buf)->st_mode)
164 #define S_TYPEISSHM(buf) ((buf)->st_mode - (buf)->st_mode)
165 #define S_TYPEISTMO(buf) (0)
166
167 // Non-POSIX; Linux-specific
168 #define S_IRWXUGO (S_IRWXU|S_IRWXG|S_IRWXO)
169 #define S_IALLUGO (S_ISUID|S_ISGID|S_ISVTX|S_IRWXUGO)
170 #define S_IRUGO (S_IRUSR|S_IRGRP|S_IROTH)
171 #define S_IWUGO (S_IWUSR|S_IWGRP|S_IWOTH)
172 #define S_IXUGO (S_IXUSR|S_IXGRP|S_IXOTH)
173
174 // Non-POSIX
175 #define S_IFDOOR 0
176 #define S_ISDOOR(m) 0
177
178 // Non-POSIX
179 #define UTIME_NOW ((1L << 30) - 1L)
180 #define UTIME_OMIT ((1L << 30) - 2L)
181
182 __END_DECLS
183 __POP_FC_STDLIB
184 #endif