source: CIVL/include/impls/stdlib.cvl@ 1aaefd4

main test-branch
Last change on this file since 1aaefd4 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
RevLine 
[3af26ac]1/* CIVL model of stdlib.c */
2
[bf584ca]3#ifndef __STDLIB_CIVL__
[3af26ac]4#define __STDLIB_CIVL__
5#include<stdlib.h>
[3ed0820]6#include<stdio.h>
7#include <pointer.cvh>
8#include <bundle.cvh>
[3af26ac]9#include<civlc.cvh>
10
[3ed0820]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}
[3af26ac]18
[3ed0820]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}
[3af26ac]32
[a3da6fb]33void free(void*ptr){
[d98b14a]34 $free(ptr);
35}
36
[a3da6fb]37int rand(){
[c84ae6e2]38 int tmp;
39
40 $havoc(&tmp);
41 return tmp;
[3af26ac]42}
43
[a3da6fb]44void srand(unsigned int seed){
[3af26ac]45}
46
[a3da6fb]47void srandom(unsigned int seed){
[3af26ac]48}
49
[a3da6fb]50long int random(){
[c84ae6e2]51 long int tmp;
52
53 $havoc(&tmp);
54 return tmp;
[3af26ac]55}
56
[a3da6fb]57void exit(int status){
[3ff27cf]58 $assert(status == 0, "erroneous exit with code %d", status);
[3af26ac]59 $exit();
60}
61
[a3da6fb]62_Noreturn void abort(void){
[bb09d30]63 $exit();
64}
65
[a3da6fb]66int abs(int x){
67 if (x >= 0)
[b1b88d8]68 return x;
69 return (-x);
70}
71
[a306ca9]72int atoi(const char *nptr){
[94c1460]73 $abstract int _atoi(const char * ptr);
74
75 return _atoi(nptr);
[a306ca9]76}
77
[c7b82fc]78#ifdef _LINUX
[a3da6fb]79int rand_r(unsigned int *seedp){
[c84ae6e2]80 int tmp;
81
82 $havoc(&tmp);
83 return tmp;
[c7b82fc]84}
85#endif
[3af26ac]86#endif
Note: See TracBrowser for help on using the repository browser.