#include #include "nss_memcache.h" #include "marshal.h" void NSMC(unmarshal_str)(char *base, size_t elements, ...) { va_list ap; char **elem = NULL; size_t count = 0; va_start(ap, elements); for (count = 0; count < elements; count++) { elem = va_arg(ap, char **); *elem = (char *)((unsigned long) base) + ((unsigned long) *elem); } } size_t NSMC(marshal_str)(char *base, size_t elements, ...) { va_list ap; size_t count = 0; char *last = base; va_start(ap, elements); for (count = 0; count < elements; count++) { char **elem = va_arg(ap, char **); /* grab the further end point used from base. */ char *end = *elem + strlen(*elem) + 1; if (end > last) last = end; *elem = (char *)labs(((unsigned long) base) - ((unsigned long) *elem)); } return (last - base); } void NSMC(unmarshal_strp)(char *base, size_t elements, ...) { va_list ap; char ***elem = NULL; size_t elems = 0, entry = 0; va_start(ap, elements); for (elems = 0; elems < elements; elems++) { elem = va_arg(ap, char ***); // iterate over char *s in char** like gr_mem for (entry = 0; *elem && (*elem)[entry] ; entry++) (*elem)[entry] = (char *)((unsigned long) base) + ((unsigned long) (*elem)[entry]); *elem = (char **)((unsigned long) base) + ((unsigned long) *elem); } } size_t NSMC(marshal_strp)(char *base, size_t elements, ...) { va_list ap; size_t elems = 0, entry = 0; char *last = 0; va_start(ap, elements); for (elems = 0; elems < elements; elems++) { char ***elem = va_arg(ap, char ***); // dereference into base *elem = (char **)labs(((unsigned long) base) - ((unsigned long) *elem)); // fix up all contained pointers for (entry = 0; *elem && (*elem)[entry] ; entry++) { char *end = *elem[entry] + strlen((*elem)[entry]) + 1; if (end > last) last = end; (*elem)[entry] = (char *)labs(((unsigned long) base) - ((unsigned long) (*elem)[entry])); } } return (last - base); }