aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
authorwelinder@troll.com <welinder@troll.com>2004-10-02 22:49:30 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-07 21:03:27 -0700
commit7a52af572ba9e8280cc28e73b575e56ab03214fd (patch)
tree2558dbdfdd45f91635d13d139bc32002f5ef951a
parent4250a6355c2a29764f5a8b31a1a22087439068dd (diff)
downloadsparse-dev-7a52af572ba9e8280cc28e73b575e56ab03214fd.tar.gz
Add compatibility file for solaris.
-rw-r--r--Makefile6
-rw-r--r--compat-linux.c52
-rw-r--r--compat-solaris.c34
-rw-r--r--compat/id-files-stat.c7
-rw-r--r--compat/mmap-blob.c33
-rw-r--r--compat/strtold.c6
6 files changed, 89 insertions, 49 deletions
diff --git a/Makefile b/Makefile
index ea6e169b..4e158b72 100644
--- a/Makefile
+++ b/Makefile
@@ -74,6 +74,12 @@ tokenize.o: $(LIB_H)
check.o: $(LIB_H)
obfuscate.o: $(LIB_H)
+compat-linux.o: compat/strtold.c compat/id-files-stat.c compat/mmap-blob.c \
+ $(LIB_H)
+compat-solaris.o: compat/id-files-stat.c compat/mmap-blob.c $(LIB_H)
+compat-mingw.o: $(LIB_H)
+compat-cygwin.o: $(LIB_H)
+
pre-process.h:
echo "#define GCC_INTERNAL_INCLUDE \"`$(CC) -print-file-name=include`\"" > pre-process.h
diff --git a/compat-linux.c b/compat-linux.c
index afa278b7..8f621ae6 100644
--- a/compat-linux.c
+++ b/compat-linux.c
@@ -1,53 +1,7 @@
-/*
- * 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;
-}
+#include "compat/id-files-stat.c"
+#include "compat/mmap-blob.c"
+#include "compat/strtold.c"
diff --git a/compat-solaris.c b/compat-solaris.c
new file mode 100644
index 00000000..d8fa1d9e
--- /dev/null
+++ b/compat-solaris.c
@@ -0,0 +1,34 @@
+#include "lib.h"
+
+#include "compat/id-files-stat.c"
+#include "compat/mmap-blob.c"
+
+
+#include <floatingpoint.h>
+#include <limits.h>
+#include <errno.h>
+
+long double string_to_ld(const char *str, char **endptr)
+{
+ long double res;
+ decimal_record dr;
+ enum decimal_string_form form;
+ decimal_mode dm;
+ fp_exception_field_type excp;
+ char *echar;
+
+ string_to_decimal ((char **)&str, INT_MAX, 0,
+ &dr, &form, &echar);
+ if (endptr) *endptr = (char *)str;
+
+ if (form == invalid_form) {
+ errno = EINVAL;
+ return 0.0;
+ }
+
+ dm.rd = fp_nearest;
+ decimal_to_quadruple (&res, &dm, &dr, &excp);
+ if (excp & ((1 << fp_overflow) | (1 << fp_underflow)))
+ errno = ERANGE;
+ return res;
+}
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);
+}