This splits existing functions which expects any argument into pairs, second being one which accepts va_list, to be used later.
Signed-off-by: Michael Tokarev <m...@tls.msk.ru> --- fsdev/virtio-9p-marshal.c | 38 ++++++++++++++++++++++++++++---------- fsdev/virtio-9p-marshal.h | 6 ++++++ 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/fsdev/virtio-9p-marshal.c b/fsdev/virtio-9p-marshal.c index 20f308b..757a79a 100644 --- a/fsdev/virtio-9p-marshal.c +++ b/fsdev/virtio-9p-marshal.c @@ -108,15 +108,13 @@ ssize_t v9fs_pack(struct iovec *in_sg, int in_num, size_t offset, return v9fs_packunpack((void *)src, in_sg, in_num, offset, size, 1); } -ssize_t v9fs_unmarshal(struct iovec *out_sg, int out_num, size_t offset, - int bswap, const char *fmt, ...) +ssize_t v9fs_vunmarshal(struct iovec *out_sg, int out_num, size_t offset, + int bswap, const char *fmt, va_list ap) { int i; - va_list ap; ssize_t copied = 0; size_t old_offset = offset; - va_start(ap, fmt); for (i = 0; fmt[i]; i++) { switch (fmt[i]) { case 'b': { @@ -212,20 +210,28 @@ ssize_t v9fs_unmarshal(struct iovec *out_sg, int out_num, size_t offset, } offset += copied; } - va_end(ap); return offset - old_offset; } -ssize_t v9fs_marshal(struct iovec *in_sg, int in_num, size_t offset, - int bswap, const char *fmt, ...) +ssize_t v9fs_unmarshal(struct iovec *in_sg, int in_num, size_t offset, + int bswap, const char *fmt, ...) { - int i; + ssize_t ret; va_list ap; + va_start(ap, fmt); + ret = v9fs_vunmarshal(in_sg, in_num, offset, bswap, fmt, ap); + va_end(ap); + return ret; +} + +ssize_t v9fs_vmarshal(struct iovec *in_sg, int in_num, size_t offset, + int bswap, const char *fmt, va_list ap) +{ + int i; ssize_t copied = 0; size_t old_offset = offset; - va_start(ap, fmt); for (i = 0; fmt[i]; i++) { switch (fmt[i]) { case 'b': { @@ -317,7 +323,19 @@ ssize_t v9fs_marshal(struct iovec *in_sg, int in_num, size_t offset, } offset += copied; } - va_end(ap); return offset - old_offset; } + +ssize_t v9fs_marshal(struct iovec *in_sg, int in_num, size_t offset, + int bswap, const char *fmt, ...) +{ + ssize_t ret; + va_list ap; + va_start(ap, fmt); + ret = v9fs_vmarshal(in_sg, in_num, offset, bswap, fmt, ap); + va_end(ap); + return ret; +} + + diff --git a/fsdev/virtio-9p-marshal.h b/fsdev/virtio-9p-marshal.h index 5df65a8..90d48ca 100644 --- a/fsdev/virtio-9p-marshal.h +++ b/fsdev/virtio-9p-marshal.h @@ -1,6 +1,8 @@ #ifndef _QEMU_VIRTIO_9P_MARSHAL_H #define _QEMU_VIRTIO_9P_MARSHAL_H +#include <stdarg.h> + typedef struct V9fsString { uint16_t size; @@ -85,6 +87,10 @@ ssize_t v9fs_pack(struct iovec *in_sg, int in_num, size_t offset, const void *src, size_t size); ssize_t v9fs_unmarshal(struct iovec *out_sg, int out_num, size_t offset, int bswap, const char *fmt, ...); +ssize_t v9fs_vunmarshal(struct iovec *out_sg, int out_num, size_t offset, + int bswap, const char *fmt, va_list ap); ssize_t v9fs_marshal(struct iovec *in_sg, int in_num, size_t offset, int bswap, const char *fmt, ...); +ssize_t v9fs_vmarshal(struct iovec *in_sg, int in_num, size_t offset, + int bswap, const char *fmt, va_list ap); #endif -- 2.1.4