--- libelwix/src/pack.c 2014/02/11 00:08:13 1.4.2.1 +++ libelwix/src/pack.c 2014/02/11 00:41:12 1.4.2.2 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: pack.c,v 1.4.2.1 2014/02/11 00:08:13 misho Exp $ +* $Id: pack.c,v 1.4.2.2 2014/02/11 00:41:12 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -262,7 +262,7 @@ rpack_uint64(rpack_t * __restrict rp, uint64_t * __res } /* - * rpack_data() - Pack/Unpack data + * rpack_data() - Pack/Unpack align data * * @rp = raw buffer * @dat = data @@ -291,5 +291,37 @@ rpack_data(rpack_t * __restrict rp, void * __restrict memcpy(next, dat, datlen); rp->r_next = next + datlen; + return buf; +} + +/* + * rpack_raw() - Pack/Unpack raw data + * + * @rp = raw buffer + * @dat = data + * @datlen = data length + * return: NULL error or != NULL get data, must be e_free() after use! + */ +void * +rpack_raw(rpack_t * __restrict rp, void * __restrict dat, size_t datlen) +{ + void *buf = NULL; + + if (!datlen || !RPACK_SANITY(rp)) + return NULL; + buf = e_malloc(datlen); + if (!buf) + return NULL; + /* No space left */ + if (datlen + rp->r_next - rp->r_buf > rp->r_len) { + e_free(buf); + return NULL; + } + + memcpy(buf, rp->r_next, datlen); + if (dat) + memcpy(rp->r_next, dat, datlen); + + rp->r_next += datlen; return buf; }