--- libelwix/src/iov.c 2021/03/19 00:40:28 1.1.2.2 +++ libelwix/src/iov.c 2021/03/19 03:01:52 1.1.2.4 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: iov.c,v 1.1.2.2 2021/03/19 00:40:28 misho Exp $ +* $Id: iov.c,v 1.1.2.4 2021/03/19 03:01:52 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -90,7 +90,7 @@ iov_Destroy(iovec_t ** __restrict iov) * return: -1 error, 0 ok */ int -iov_Get(iovec_t * __restrict iov, u_int pos, void **data, size_t *datlen) +iov_Get(iovec_t * __restrict iov, u_int pos, void *data, size_t *datlen) { if (!iov || !data || !datlen) return -1; @@ -99,7 +99,7 @@ iov_Get(iovec_t * __restrict iov, u_int pos, void **da return -1; *datlen = MIN(*datlen, iov->iov_array[pos].iov_len); - memcpy(*data, iov->iov_array[pos].iov_base, *datlen); + memcpy(data, iov->iov_array[pos].iov_base, *datlen); return 0; } @@ -195,13 +195,16 @@ iov_Push(iovec_t * __restrict iov, void *data, size_t * return: -1 error, !=-1 poped from position */ int -iov_Pop(iovec_t * __restrict iov, void **data, size_t *datlen, int mustfree) +iov_Pop(iovec_t * __restrict iov, void *data, size_t *datlen, int mustfree) { register int pos; if (!iov) return -1; + if (iov->iov_size < 1) + return 0; + for (pos = iov->iov_size - 1; pos >= 0; pos--) if (iov->iov_array[pos].iov_base) break; @@ -263,16 +266,17 @@ iov_PushPair(iovec_t * __restrict iov, const char *nam * return: -1 error, !=-1 poped from position */ int -iov_PopPair(iovec_t * __restrict iov, char **name, size_t *namlen, void **data, size_t *datlen) +iov_PopPair(iovec_t * __restrict iov, char *name, size_t *namlen, + void *data, size_t *datlen, int mustfree) { int pos; if (!iov) return -1; - if (iov_Pop(iov, data, datlen, 0) == -1) + if (iov_Pop(iov, data, datlen, mustfree) == -1) return -1; - if ((pos = iov_Pop(iov, (void**) name, namlen, 42)) == -1) + if ((pos = iov_Pop(iov, name, namlen, 42)) == -1) return -1; return pos; @@ -292,6 +296,7 @@ iov_Debug(iovec_t * __restrict iov) if (!iov) return; + printf("iov_size=%zu iov_array=%p\n", iov->iov_size, iov->iov_array); for (pos = 0; pos < iov->iov_size; pos++) printf("IOVEC[%zu] base=%p len=%zu (%s)\n", pos, iov->iov_array[pos].iov_base, iov->iov_array[pos].iov_len, (char*) iov->iov_array[pos].iov_base);