aboutsummaryrefslogblamecommitdiffstats
path: root/libpatch_append_to_patch__.c
blob: cf54c6f7cd87946ef0187bbe1803104540fd9e2e (plain) (tree)



























                                                                                         
/* 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;
}