aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2004-09-25 12:58:47 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-07 21:03:22 -0700
commit3f5a1da9cced68a0c945a755f120da25f6d264e6 (patch)
treed9b8f81a02d5faff35c0cea92340656c94eb1a31 /compat-linux.c
parent[PATCH] Use $(CC) everywhere in Makefile. (diff)
downloadsparse-3f5a1da9cced68a0c945a755f120da25f6d264e6.tar.gz
sparse-3f5a1da9cced68a0c945a755f120da25f6d264e6.tar.bz2
sparse-3f5a1da9cced68a0c945a755f120da25f6d264e6.zip
Add system-specific compatibility functions to make
up for various system deficiencies. This makes sparse easier to port to silly things like MinGW or Solaris. In particular: - strtold() is a C99 thing, not everybody has it - MinGW has problems with mmap(MAP_ANONYMOUS) and doesn't zero it. - st_ino/st_dev is POSIX identity testing, not supported by MinGW
Diffstat (limited to 'compat-linux.c')
-rw-r--r--compat-linux.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/compat-linux.c b/compat-linux.c
new file mode 100644
index 0000000..afa278b
--- /dev/null
+++ b/compat-linux.c
@@ -0,0 +1,53 @@
+/*
+ * Sane compat.c for Linux
+ */
+#define _GNU_SOURCE
+
+#include <stdlib.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include "lib.h"
+#include "token.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);
+}
+
+long double string_to_ld(const char *nptr, char **endptr)
+{
+ return strtold(nptr, endptr);
+}
+
+int identical_files(struct stream* s, struct stat *st, const char * name)
+{
+ return s->dev == st->st_dev && s->ino == st->st_ino;
+}