Skip to content
Snippets Groups Projects
Commit 10de818a authored by Mark Grondona's avatar Mark Grondona
Browse files

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
parent 84fa57e2
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
......@@ -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 */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment