[2701] in BarnOwl Developers

home help back first fref pref prev next nref lref last post

[PATCH] Add a compatibility implementation of memrchr

daemon@ATHENA.MIT.EDU (David Benjamin)
Sun Oct 3 21:16:15 2010

From: David Benjamin <davidben@MIT.EDU>
To: barnowl-dev@mit.edu
Date: Sun,  3 Oct 2010 21:15:43 -0400

It's a GNU extension and not available on Solaris.
---
 Makefile.am        |    6 +++---
 compat/Makefile.am |    4 ++++
 compat/compat.h    |    7 +++++++
 compat/memrchr.c   |   11 +++++++++++
 configure.ac       |    5 ++++-
 owl.h              |    2 ++
 6 files changed, 31 insertions(+), 4 deletions(-)
 create mode 100644 compat/Makefile.am
 create mode 100644 compat/compat.h
 create mode 100644 compat/memrchr.c

diff --git a/Makefile.am b/Makefile.am
index 3d34f13..c70ec13 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -21,14 +21,14 @@ barnowl_bin_SOURCES = $(BASE_SRCS) \
 man_MANS = doc/barnowl.1
 doc_DATA = doc/intro.txt doc/advanced.txt
 
-barnowl_bin_LDADD = libfaim/libfaim.a
+barnowl_bin_LDADD = compat/libcompat.a libfaim/libfaim.a
 
 tester_bin_SOURCES = $(BASE_SRCS) \
      owl.h owl_perl.h config.h \
      $(GEN_C) $(GEN_H) \
      tester.c
 
-tester_bin_LDADD = libfaim/libfaim.a
+tester_bin_LDADD = compat/libcompat.a libfaim/libfaim.a
 
 TESTS=runtests.sh
 
@@ -87,4 +87,4 @@ install-exec-hook:
 	mv -f $(DESTDIR)$(bindir)/$(call do_transform,barnowl.bin) \
 	      $(DESTDIR)$(bindir)/$(call do_transform,barnowl)
 
-SUBDIRS = libfaim perl
+SUBDIRS = compat libfaim perl
diff --git a/compat/Makefile.am b/compat/Makefile.am
new file mode 100644
index 0000000..7ac4486
--- /dev/null
+++ b/compat/Makefile.am
@@ -0,0 +1,4 @@
+noinst_LIBRARIES = libcompat.a
+
+libcompat_a_SOURCES =
+libcompat_a_LIBADD = $(LIBOBJS)
diff --git a/compat/compat.h b/compat/compat.h
new file mode 100644
index 0000000..8ad61e6
--- /dev/null
+++ b/compat/compat.h
@@ -0,0 +1,7 @@
+#include "../config.h"
+
+#include <stddef.h>
+
+#ifndef HAVE_MEMRCHR
+void *memrchr(const void *s, int c, size_t n);
+#endif  /* HAVE_MEMRCHR */
diff --git a/compat/memrchr.c b/compat/memrchr.c
new file mode 100644
index 0000000..773cf6f
--- /dev/null
+++ b/compat/memrchr.c
@@ -0,0 +1,11 @@
+#include "compat.h"
+
+void *memrchr(const void *s, int c, size_t n) {
+  int i;
+  const unsigned char *ss = s;
+  for (i = n-1; i >= 0; i--) {
+    if (ss[i] == (unsigned char)c)
+      return ss + i;
+  }
+  return NULL;
+}
diff --git a/configure.ac b/configure.ac
index 95983be..fae17ec 100644
--- a/configure.ac
+++ b/configure.ac
@@ -154,5 +154,8 @@ if test "x${HAVE_ZIP}" = "xno"; then
    AC_MSG_ERROR([cannot find a 'zip' binary.])
 fi
 
-AC_CONFIG_FILES([Makefile libfaim/Makefile perl/Makefile perl/modules/Makefile])
+AC_CONFIG_LIBOBJ_DIR([compat])
+AC_REPLACE_FUNCS([memrchr])
+
+AC_CONFIG_FILES([Makefile compat/Makefile libfaim/Makefile perl/Makefile perl/modules/Makefile])
 AC_OUTPUT
diff --git a/owl.h b/owl.h
index 8d6ca37..3685a79 100644
--- a/owl.h
+++ b/owl.h
@@ -11,6 +11,8 @@
 
 #include "config.h"
 
+#include "compat/compat.h"
+
 #ifdef HAVE_STDBOOL_H
 #include <stdbool.h>
 #else
-- 
1.7.3.1.g716de


home help back first fref pref prev next nref lref last post