about summary refs log tree commit diff
path: root/lib/util/nstring.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/util/nstring.h')
-rw-r--r--lib/util/nstring.h82
1 files changed, 64 insertions, 18 deletions
diff --git a/lib/util/nstring.h b/lib/util/nstring.h
index 9ed20051..53f1e4c0 100644
--- a/lib/util/nstring.h
+++ b/lib/util/nstring.h
@@ -5,6 +5,7 @@
 #include <string.h>
 #include <ctype.h>
 
+#include "pm_c_util.h"
 #include "pm.h"  /* For PM_GNU_PRINTF_ATTR, __inline__ */
 
 #ifdef __cplusplus
@@ -14,7 +15,7 @@ extern "C" {
 } /* to fake out automatic code indenters */
 #endif
 
-/* Here is are string functions that respect the size of the array
+/* Here are string functions that respect the size of the array
    into which you are copying -- E.g. STRSCPY truncates the source string as
    required so that it fits, with the terminating null, in the destination
    array.
@@ -25,22 +26,18 @@ extern "C" {
 	(strncmp((A), (B), sizeof(A)))
 #define STRSCAT(A,B) \
     (strncpy(A+strlen(A), B, sizeof(A)-strlen(A)), *((A)+sizeof(A)-1) = '\0')
-
-#define STREQ(A, B) \
-    (strcmp((A), (B)) == 0)
-#define STRNEQ(A, B, C) \
-    (strncmp((A), (B), (C)) == 0)
-#define STRCASEEQ(A, B) \
-    (strcasecmp((A), (B)) == 0)
-#define STRNCASEEQ(A, B, C) \
-    (strncasecmp((A), (B), (C)) == 0)
 #define STRSEQ(A, B) \
-	(strncmp((A), (B), sizeof(A)) == 0)
+	(strneq((A), (B), sizeof(A)))
+
+#define MEMEQ(a,b,c) (memcmp(a, b, c) == 0)
+
+#define MEMSEQ(a,b) (memeq(a, b, sizeof(*(a))) == 0)
+
+#define MEMSSET(a,b) (memset(a, b, sizeof(*(a))))
 
-#define MEMEQ(A, B, C) \
-    (memcmp((A), (B), (C)) == 0)
-#define MEMSZERO(A) \
-    bzero((A), sizeof(A))
+#define MEMSCPY(a,b) (memcpy(a, b, sizeof(*(a))))
+
+#define MEMSZERO(a) (MEMSSET(a, 0))
 
 
 static __inline__ int
@@ -50,6 +47,42 @@ streq(const char * const comparand,
     return strcmp(comparand, comparator) == 0;
 }
 
+static __inline__ int
+strneq(const char * const comparand,
+       const char * const comparator,
+       size_t       const size) {
+
+    return strncmp(comparand, comparator, size) == 0;
+}
+
+static __inline__ int
+memeq(const void * const comparand,
+      const void * const comparator,
+      size_t       const size) {
+    
+    return memcmp(comparand, comparator, size) == 0;
+}
+
+/* The Standard C Library may not declare strcasecmp() if the including
+   source file doesn't request BSD functions, with _BSD_SOURCE.  So
+   we don't define functions that use strcasecmp() in that case.
+*/
+#ifdef _BSD_SOURCE
+static __inline__ int
+strcaseeq(const char * const comparand,
+          const char * const comparator) {
+
+    return strcasecmp(comparand, comparator) == 0;
+}
+
+static __inline__ int
+strncaseeq(const char * const comparand,
+           const char * const comparator,
+           size_t       const size) {
+
+    return strncasecmp(comparand, comparator, size) == 0;
+}
+#endif
 
 
 /* The standard C library routines isdigit(), for some weird 
@@ -134,6 +167,11 @@ asprintfN(const char ** const resultP,
           const char *  const fmt,
           ...) PM_GNU_PRINTF_ATTR(2,3);
 
+void
+vasprintfN(const char ** const resultP,
+           const char *  const format,
+           va_list             args);
+
 void 
 strfree(const char * const string);
 
@@ -144,12 +182,20 @@ int
 stripeq(const char * const comparand,
         const char * const comparator);
 
-const char *
-memmemN(const char * const haystack,
+const void *
+memmemN(const void * const haystackArg,
         size_t       const haystacklen,
-        const char * const needle,
+        const void * const needleArg,
         size_t       const needlelen);
 
+bool
+strishex(const char * const subject);
+
+void
+interpret_uint(const char *   const string,
+               unsigned int * const valueP,
+               const char **  const errorP);
+
 #ifdef __cplusplus
 }
 #endif