memrchr is missing ?

Werner Koch wk at gnupg.org
Thu Oct 19 10:25:44 CEST 2006


On Thu, 19 Oct 2006 05:17, ARIGA Seiji said:

> it seems to me that memrchr() is missing on platform where standard
> library doesn't have it.

Right.  Here is an untested fix:


2006-10-19  Werner Koch  <wk at g10code.com>

       * stringhelp.c (memrchr) [!HAVE_MEMRCHR]: Provide a replacement.

 
        * mischelp.c: New.
Index: jnlib/stringhelp.c
===================================================================
--- jnlib/stringhelp.c  (revision 4307)
+++ jnlib/stringhelp.c  (working copy)
@@ -796,3 +796,15 @@
 #endif
 
 
+#ifndef HAVE_MEMRCHR
+void *
+memrchr (const void *buffer, int c, size_t n)
+{
+  const unsigned char *p = buffer;
+
+  for (p += n; n ; n--)
+    if (*--p == c)
+      return p;
+  return NULL;
+}
+#endif /*HAVE_MEMRCHR*/
Index: jnlib/stringhelp.h
===================================================================
--- jnlib/stringhelp.h  (revision 4307)
+++ jnlib/stringhelp.h  (working copy)
@@ -95,7 +95,11 @@
 #ifndef HAVE_STRICMP
 #  define stricmp(a,b)  strcasecmp( (a), (b) )
 #endif
+#ifndef HAVE_MEMRCHR
+void *memrchr (const void *buffer, int c, size_t n);
+#endif
 
+
 #ifndef HAVE_ISASCII
 static inline int 
 isascii (int c)




More information about the Gnupg-devel mailing list