diff options
Diffstat (limited to 'compat')
| -rw-r--r-- | compat/id-files-stat.c | 7 | ||||
| -rw-r--r-- | compat/mmap-blob.c | 33 | ||||
| -rw-r--r-- | compat/strtold.c | 6 |
3 files changed, 46 insertions, 0 deletions
diff --git a/compat/id-files-stat.c b/compat/id-files-stat.c new file mode 100644 index 00000000..62f0f57e --- /dev/null +++ b/compat/id-files-stat.c @@ -0,0 +1,7 @@ +#include "../token.h" +#include <sys/stat.h> + +int identical_files(struct stream* s, struct stat *st, const char * name) +{ + return s->dev == st->st_dev && s->ino == st->st_ino; +} diff --git a/compat/mmap-blob.c b/compat/mmap-blob.c new file mode 100644 index 00000000..6ddcd84a --- /dev/null +++ b/compat/mmap-blob.c @@ -0,0 +1,33 @@ +#include <sys/mman.h> +#include <sys/types.h> + +/* + * Allow old BSD naming too, it would be a pity to have to make a + * separate file just for this. + */ +#ifndef MAP_ANONYMOUS +#define MAP_ANONYMOUS MAP_ANON +#endif + +/* + * Our blob allocator enforces the strict CHUNK size + * requirement, as a portability check. + */ +void *blob_alloc(unsigned long size) +{ + void *ptr; + + if (size & ~CHUNK) + die("internal error: bad allocation size (%d bytes)", size); + ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (ptr == MAP_FAILED) + ptr = NULL; + return ptr; +} + +void blob_free(void *addr, unsigned long size) +{ + if (!size || (size & ~CHUNK) || ((unsigned long) addr & 512)) + die("internal error: bad blob free (%d bytes at %p)", size, addr); + munmap(addr, size); +} diff --git a/compat/strtold.c b/compat/strtold.c new file mode 100644 index 00000000..1b6ad7d5 --- /dev/null +++ b/compat/strtold.c @@ -0,0 +1,6 @@ +#include <stdlib.h> + +long double string_to_ld(const char *nptr, char **endptr) +{ + return strtold(nptr, endptr); +} |
