source: CIVL/include/impls/stdlib.cvl@ 6329dc1

main test-branch
Last change on this file since 6329dc1 was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 1.3 KB
Line 
1/* CIVL model of stdlib.c */
2
3#ifndef __STDLIB_CIVL__
4#define __STDLIB_CIVL__
5#include<stdlib.h>
6#include<stdio.h>
7#include <pointer.cvh>
8#include <bundle.cvh>
9#include<civlc.cvh>
10
11void swap(void * a, void * b, size_t size) {
12 $bundle bun_a = $bundle_pack(a, size);
13 $bundle bun_b = $bundle_pack(b, size);
14
15 $bundle_unpack(bun_a, b);
16 $bundle_unpack(bun_b, a);
17}
18
19void qsort(void *base, size_t n, size_t es,
20 int (*cmp)(const void*, const void*)) {
21 for (int i = 1; i < n; i++) {
22 for (int j = i; j > 0; j--) {
23 void * p_j_1 = $pointer_add(base, j-1, es);
24 void * p_j = $pointer_add(base, j, es);
25 int comp = cmp(p_j_1, p_j);
26
27 if (comp <= 0) continue;
28 else swap(p_j_1, p_j, es);
29 }
30 }
31}
32
33void free(void*ptr){
34 $free(ptr);
35}
36
37int rand(){
38 int tmp;
39
40 $havoc(&tmp);
41 return tmp;
42}
43
44void srand(unsigned int seed){
45}
46
47void srandom(unsigned int seed){
48}
49
50long int random(){
51 long int tmp;
52
53 $havoc(&tmp);
54 return tmp;
55}
56
57void exit(int status){
58 $assert(status == 0, "erroneous exit with code %d", status);
59 $exit();
60}
61
62_Noreturn void abort(void){
63 $exit();
64}
65
66int abs(int x){
67 if (x >= 0)
68 return x;
69 return (-x);
70}
71
72int atoi(const char *nptr){
73 $abstract int _atoi(const char * ptr);
74
75 return _atoi(nptr);
76}
77
78#ifdef _LINUX
79int rand_r(unsigned int *seedp){
80 int tmp;
81
82 $havoc(&tmp);
83 return tmp;
84}
85#endif
86#endif
Note: See TracBrowser for help on using the repository browser.