diff options
Diffstat (limited to 'libpatch_append_to_patch__.c')
-rw-r--r-- | libpatch_append_to_patch__.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/libpatch_append_to_patch__.c b/libpatch_append_to_patch__.c new file mode 100644 index 0000000..cf54c6f --- /dev/null +++ b/libpatch_append_to_patch__.c @@ -0,0 +1,28 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + + +int +libpatch_append_to_patch__(struct libpatch_patch **patch, size_t *patchlen, size_t *size, + size_t stroff, size_t strlen, int type) +{ + void *new; + if (*patchlen < *size) { + if (*size > SIZE_MAX / sizeof(**patch) - 70) { + errno = ENOMEM; + return -1; + } + new = realloc(*patch, (*size + 70) * sizeof(**patch)); + if (!new) + return -1; + *patch = new; + *size += 70; + memset(&(*patch)[*patchlen], 0, 70 * sizeof(**patch)); + } + (*patch)[*patchlen].type = type; + (*patch)[*patchlen].text_offset = stroff; + (*patch)[*patchlen].text_length = strlen; + (*patch)[*patchlen].lf_terminated = 1; + *patchlen += 1; + return 0; +} |