CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
unistd.c
Go to the documentation of this file.
1/* FUNCTION: sleep */
2
4
5unsigned int sleep(unsigned int seconds)
6{
8 // do nothing, but return nondet value
11
12 return remaining_time;
13}
14
15/* FUNCTION: _sleep */
16
17unsigned int sleep(unsigned int seconds);
18
19unsigned int _sleep(unsigned int seconds)
20{
22 return sleep(seconds);
23}
24
25/* FUNCTION: usleep */
26
27#ifndef __CPROVER_ERRNO_H_INCLUDED
28# include <errno.h>
29# define __CPROVER_ERRNO_H_INCLUDED
30#endif
31
33
34int usleep(unsigned int usec)
35{
37 // do nothing, but return nondet value
39 if(error)
40 {
41 if(usec >= 1000000)
42 errno = EINVAL;
43 else
44 errno = EINTR;
45 return -1;
46 }
47 return 0;
48}
49
50/* FUNCTION: _usleep */
51
52int usleep(unsigned int);
53
54int _usleep(unsigned int usec)
55{
57 return usleep(usec);
58}
59
60/* FUNCTION: unlink */
61
63
64int unlink(const char *s)
65{
67 (void)*s;
68 #ifdef __CPROVER_STRING_ABSTRACTION
70 "unlink zero-termination");
71 #endif
73 return retval;
74}
75
76/* FUNCTION: pipe */
77
78#ifndef __CPROVER_ERRNO_H_INCLUDED
79#include <errno.h>
80#define __CPROVER_ERRNO_H_INCLUDED
81#endif
82
84// offset to make sure we don't collide with other fds
85extern const int __CPROVER_pipe_offset;
87
89
117
118/* FUNCTION: _pipe */
119
120#ifdef _WIN32
121#undef pipe
122int pipe(int fildes[2]);
123
124int _pipe(int *pfds, unsigned int psize, int textmode)
125{
127 (void)psize;
128 (void)textmode;
129 return pipe(pfds);
130}
131#endif
132
133/* FUNCTION: close */
134
136// offset to make sure we don't collide with other fds
137extern const int __CPROVER_pipe_offset;
138
139int close(int fildes)
140{
142 if((fildes>=0 && fildes<=2) || fildes < __CPROVER_pipe_offset)
143 return 0;
144
146
147 int retval=-1;
149 if(fildes%2==1)
150 --fildes;
153 {
154 __CPROVER_pipes[fildes].widowed=1;
155 __CPROVER_pipes[fildes].next_avail=__CPROVER_pipes[fildes].next_unread=0;
156 retval=0;
157 }
159 return retval;
160}
161
162/* FUNCTION: _close */
163
164int close(int fildes);
165
167{
169 return close(fildes);
170}
171
172/* FUNCTION: write */
173
174// do not include unistd.h as this might trigger GCC asm renaming of
175// write to _write; this is covered by the explicit definition of
176// _write below
177#ifdef _MSC_VER
178#define ret_type int
179#define size_type unsigned
180#else
181#ifndef __CPROVER_SYS_TYPES_H_INCLUDED
182#include <sys/types.h>
183#define __CPROVER_SYS_TYPES_H_INCLUDED
184#endif
185#define ret_type ssize_t
186#define size_type size_t
187#endif
188
190// offset to make sure we don't collide with other fds
191extern const int __CPROVER_pipe_offset;
192
194
196{
198 if((fildes>=0 && fildes<=2) || fildes < __CPROVER_pipe_offset)
199 {
202 return retval;
203 }
204
206
207 int retval=-1;
209 if(fildes%2==1)
210 --fildes;
212 if(
215 sizeof(__CPROVER_pipes[fildes].data) >=
217 {
218 for(size_type i=0; i<nbyte; ++i)
220 ((char*)buf)[i];
221 __CPROVER_pipes[fildes].next_avail+=nbyte;
223 }
225 return retval;
226}
227
228/* FUNCTION: _write */
229
230#ifdef _MSC_VER
231#define ret_type int
232#define size_type unsigned
233#else
234#ifndef __CPROVER_SYS_TYPES_H_INCLUDED
235#include <sys/types.h>
236#define __CPROVER_SYS_TYPES_H_INCLUDED
237#endif
238#define ret_type ssize_t
239#define size_type size_t
240#endif
241
242ret_type write(int fildes, const void *buf, size_type nbyte);
243
245{
247 return write(fildes, buf, nbyte);
248}
249
250/* FUNCTION: read */
251
252// do not include unistd.h as this might trigger GCC asm renaming of
253// read to _read; this is covered by the explicit definition of _read
254// below
255#ifdef _MSC_VER
256#define ret_type int
257#define size_type unsigned
258#else
259#ifndef __CPROVER_SYS_TYPES_H_INCLUDED
260#include <sys/types.h>
261#define __CPROVER_SYS_TYPES_H_INCLUDED
262#endif
263#define ret_type ssize_t
264#define size_type size_t
265#endif
266
268// offset to make sure we don't collide with other fds
269extern const int __CPROVER_pipe_offset;
270
274
276{
278 if((fildes>=0 && fildes<=2) || fildes < __CPROVER_pipe_offset)
279 {
282
284#if 0
285 size_type i;
286 for(i=0; i<nbyte; i++)
287 {
288 char nondet_char;
289 ((char *)buf)[i]=nondet_char;
290 }
291#else
292 if(nbyte>0)
293 {
296 // check that the memory is accessible
297 (void)*(char *)buf;
298 (void)*(((const char *)buf) + str_length - 1);
301 }
302#endif
303
304 return error ? -1 : nread;
305 }
306
308
309 int retval=0;
311 if(fildes%2==1)
312 --fildes;
314 if(
317 {
318 for(size_type i=0; i<nbyte &&
319 __CPROVER_pipes[fildes].next_unread <
320 __CPROVER_pipes[fildes].next_avail;
321 ++i)
322 {
323 ((char*)buf)[i]=__CPROVER_pipes[fildes].
324 data[__CPROVER_pipes[fildes].next_unread];
325 ++__CPROVER_pipes[fildes].next_unread;
326 ++retval;
327 }
330 __CPROVER_pipes[fildes].next_avail=__CPROVER_pipes[fildes].next_unread=0;
331 }
333 return retval;
334}
335
336/* FUNCTION: _read */
337
338#ifdef _MSC_VER
339#define ret_type int
340#define size_type unsigned
341#else
342#ifndef __CPROVER_SYS_TYPES_H_INCLUDED
343#include <sys/types.h>
344#define __CPROVER_SYS_TYPES_H_INCLUDED
345#endif
346#define ret_type ssize_t
347#define size_type size_t
348#endif
349
351
353{
355 return read(fildes, buf, nbyte);
356}
357
358/* FUNCTION: sysconf */
359
360#ifndef __CPROVER_ERRNO_H_INCLUDED
361# include <errno.h>
362# define __CPROVER_ERRNO_H_INCLUDED
363#endif
364
366int __VERIFIER_nondet_int(void);
367
368long sysconf(int name);
369
370// This overapproximation is based on the sysconf specification available at
371// https://pubs.opengroup.org/onlinepubs/9699919799/functions/sysconf.html.
372long sysconf(int name)
373{
375 (void)name;
377
378 // We should keep errno as non-deterministic as possible, since this model
379 // never takes into account the name input.
381
382 // Spec states "some returned values may be huge; they are not suitable
383 // for allocating memory". There aren't also guarantees about return
384 // values being strictly equal or greater to -1.
385 // Thus, modelling it as non-deterministic.
386 return retval;
387}
#define __CPROVER_constant_infinity_uint
Definition cprover.h:21
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
void __CPROVER_array_replace(const void *dest, const void *src)
void __CPROVER_precondition(__CPROVER_bool precondition, const char *description)
_Bool __CPROVER_is_zero_string(const void *)
void __CPROVER_atomic_begin(void)
void __CPROVER_atomic_end(void)
void __CPROVER_assume(__CPROVER_bool assumption)
int __CPROVER_ID java::java io InputStream read
Definition java.io.c:5
short next_unread
Definition cprover.h:43
short next_avail
Definition cprover.h:42
_Bool widowed
Definition cprover.h:40
char data[4]
Definition cprover.h:41
int _usleep(unsigned int usec)
Definition unistd.c:54
int __VERIFIER_nondet_int(void)
unsigned __VERIFIER_nondet_unsigned(void)
#define ret_type
Definition unistd.c:185
unsigned int _sleep(unsigned int seconds)
Definition unistd.c:19
size_t __VERIFIER_nondet_size_type(void)
int _close(int fildes)
Definition unistd.c:166
ssize_t _write(int fildes, const void *buf, size_t nbyte)
Definition unistd.c:244
long sysconf(int name)
Definition unistd.c:372
unsigned int sleep(unsigned int seconds)
Definition unistd.c:5
ssize_t _read(int fildes, void *buf, size_t nbyte)
Definition unistd.c:352
unsigned __CPROVER_pipe_count
Definition unistd.c:86
ssize_t __VERIFIER_nondet_ret_type(void)
__CPROVER_bool __VERIFIER_nondet___CPROVER_bool(void)
const int __CPROVER_pipe_offset
Definition unistd.c:137
int usleep(unsigned int usec)
Definition unistd.c:34
ssize_t write(int fildes, const void *buf, size_t nbyte)
Definition unistd.c:195
int close(int fildes)
Definition unistd.c:139
#define size_type
Definition unistd.c:186
int pipe(int fildes[2])
Definition unistd.c:90
int unlink(const char *s)
Definition unistd.c:64
struct __CPROVER_pipet __CPROVER_pipes[__CPROVER_constant_infinity_uint]
Definition unistd.c:135
long __VERIFIER_nondet_long(void)