From 10de818aa1ae6dd193538fe5b37186dc9b419eb5 Mon Sep 17 00:00:00 2001
From: Mark Grondona <mgrondona@llnl.gov>
Date: Wed, 8 May 2002 16:54:26 +0000
Subject: [PATCH]  o changed name of (un)packstr to more general (un)packmem,
 (un)packstr*    are now macros that call the *mem functions  o removed
 unneeded size argument from packstr

---
 src/common/pack.c |  6 +++---
 src/common/pack.h | 36 +++++++++++++++++++++++++-----------
 2 files changed, 28 insertions(+), 14 deletions(-)

diff --git a/src/common/pack.c b/src/common/pack.c
index 1fd3e4b3fea..076914b1aa3 100644
--- a/src/common/pack.c
+++ b/src/common/pack.c
@@ -85,7 +85,7 @@ _unpack16(uint16_t *valp, void **bufp, int *lenp)
  * (size of size_val) plus the value of size_val.
  */
 void
-_packstr(char *valp, uint16_t size_val, void **bufp, int *lenp)
+_packmem(char *valp, uint16_t size_val, void **bufp, int *lenp)
 {
 	uint16_t nl = htons(size_val);
 
@@ -110,7 +110,7 @@ _packstr(char *valp, uint16_t size_val, void **bufp, int *lenp)
  *	the data is not made
  */
 void
-_unpackstr_ptr(char **valp, uint16_t *size_valp, void **bufp, int *lenp)
+_unpackmem_ptr(char **valp, uint16_t *size_valp, void **bufp, int *lenp)
 {
 	uint16_t nl;
 
@@ -141,7 +141,7 @@ _unpackstr_ptr(char **valp, uint16_t *size_valp, void **bufp, int *lenp)
  *	if non-NULL (set to NULL on zero size buffer value)
  */
 void
-_unpackstr_xmalloc(char **valp, uint16_t *size_valp, void **bufp, int *lenp)
+_unpackmem_xmalloc(char **valp, uint16_t *size_valp, void **bufp, int *lenp)
 {
 	uint16_t nl;
 
diff --git a/src/common/pack.h b/src/common/pack.h
index b877552ef63..433b593d112 100644
--- a/src/common/pack.h
+++ b/src/common/pack.h
@@ -13,7 +13,9 @@
 #    include <stdint.h>
 #  endif
 #endif  /* HAVE_INTTYPES_H */
-#endif  /* HAVE_CONFIG_H   */
+#else   /* !HAVE_CONFIG_H */
+#include <stdint.h>
+#endif  /* HAVE_CONFIG_H */
 
 #include <assert.h>
 
@@ -23,9 +25,9 @@ void	_unpack32(uint32_t *valp, void **bufp, int *lenp);
 void	_pack16(uint16_t val, void **bufp, int *lenp);
 void	_unpack16(uint16_t *valp, void **bufp, int *lenp);
 
-void	_packstr(char *valp, uint16_t size_val, void **bufp, int *lenp);
-void	_unpackstr_ptr(char **valp, uint16_t *size_valp, void **bufp, int *lenp);
-void	_unpackstr_xmalloc(char **valp, uint16_t *size_valp, void **bufp, int *lenp);
+void	_packmem(char *valp, uint16_t size_val, void **bufp, int *lenp);
+void	_unpackmem_ptr(char **valp, uint16_t *size_valp, void **bufp, int *lenp);
+void	_unpackmem_xmalloc(char **valp, uint16_t *size_valp, void **bufp, int *lenp);
 
 #define pack32(val,bufp,lenp) do {			\
 	assert(sizeof(val) == sizeof(uint32_t)); 	\
@@ -61,31 +63,43 @@ void	_unpackstr_xmalloc(char **valp, uint16_t *size_valp, void **bufp, int *lenp
 	_unpack16(valp,bufp,lenp);			\
 } while (0)
 
-#define packstr(valp,size_val,bufp,lenp) do {		\
+#define packmem(valp,size_val,bufp,lenp) do {		\
 	assert(size_val == 0 || valp != NULL);		\
-	assert(sizeof(size_val) == sizeof(uint16_t));	\
 	assert((bufp) != NULL && *(bufp) != NULL);	\
         assert((lenp) != NULL);				\
         assert(*(lenp) >= (sizeof(size_val)+size_val));	\
-	_packstr(valp,size_val,bufp,lenp);		\
+	_packmem(valp,(uint16_t)size_val,bufp,lenp);	\
 } while (0)
 
-#define unpackstr_ptr(valp,size_valp,bufp,lenp) do {	\
+#define packstr(str,bufp,lenp) do {			\
+	uint16_t _size = (uint16_t)(strlen(str)+1);	\
+        assert(_size == 0 || str != NULL);		\
+	assert((bufp) != NULL && *(bufp) != NULL);	\
+        assert((lenp) != NULL);				\
+        assert(*(lenp) >= (sizeof(_size)+_size));	\
+	_packmem(str,(uint16_t)_size,bufp,lenp);	\
+} while (0)				
+
+#define unpackmem_ptr(valp,size_valp,bufp,lenp) do {	\
 	assert(valp != NULL);				\
 	assert(sizeof(size_valp) == sizeof(uint16_t *));\
 	assert((bufp) != NULL && *(bufp) != NULL);	\
         assert((lenp) != NULL);				\
         assert(*(lenp) >= sizeof(uint32_t));		\
-	_unpackstr_ptr(valp,size_valp,bufp,lenp);	\
+	_unpackmem_ptr(valp,(uint16_t *)size_valp,bufp,lenp);\
 } while (0)
 
-#define unpackstr_xmalloc(valp,size_valp,bufp,lenp) do {\
+#define unpackstr_ptr		unpackmem_ptr
+
+#define unpackmem_xmalloc(valp,size_valp,bufp,lenp) do {\
 	assert(valp != NULL);				\
 	assert(sizeof(size_valp) == sizeof(uint16_t *));\
 	assert((bufp) != NULL && *(bufp) != NULL);	\
         assert((lenp) != NULL);				\
         assert(*(lenp) >= sizeof(uint32_t));		\
-	_unpackstr_xmalloc(valp,size_valp,bufp,lenp);	\
+	_unpackmem_xmalloc(valp,(uint16_t *)size_valp,bufp,lenp);\
 } while (0)
 
+#define unpackstr_xmalloc	unpackmem_xmalloc
+
 #endif /* _PACK_INCLUDED */
-- 
GitLab