[PATCH] two-arguments ?:
[smatch.git] / compat-linux.c
blobafa278b7e2bfb9533613cf66e40b69f6729959f5
1 /*
2 * Sane compat.c for Linux
3 */
4 #define _GNU_SOURCE
6 #include <stdlib.h>
7 #include <sys/mman.h>
8 #include <sys/types.h>
9 #include <sys/stat.h>
11 #include "lib.h"
12 #include "token.h"
15 * Allow old BSD naming too, it would be a pity to have to make a
16 * separate file just for this.
18 #ifndef MAP_ANONYMOUS
19 #define MAP_ANONYMOUS MAP_ANON
20 #endif
23 * Our blob allocator enforces the strict CHUNK size
24 * requirement, as a portability check.
26 void *blob_alloc(unsigned long size)
28 void *ptr;
30 if (size & ~CHUNK)
31 die("internal error: bad allocation size (%d bytes)", size);
32 ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
33 if (ptr == MAP_FAILED)
34 ptr = NULL;
35 return ptr;
38 void blob_free(void *addr, unsigned long size)
40 if (!size || (size & ~CHUNK) || ((unsigned long) addr & 512))
41 die("internal error: bad blob free (%d bytes at %p)", size, addr);
42 munmap(addr, size);
45 long double string_to_ld(const char *nptr, char **endptr)
47 return strtold(nptr, endptr);
50 int identical_files(struct stream* s, struct stat *st, const char * name)
52 return s->dev == st->st_dev && s->ino == st->st_ino;