aboutsummaryrefslogtreecommitdiffstats
path: root/libpatch_append_to_patch__.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2024-01-09 22:04:24 +0100
committerMattias Andrée <maandree@kth.se>2024-01-09 22:04:24 +0100
commitae850b1ac755f471beac4dbfef4654fe3fbaaae9 (patch)
tree319e7f7f1b99cd1ee75e100f0a29b0f7c827ccea /libpatch_append_to_patch__.c
downloadlibpatch-master.tar.gz
libpatch-master.tar.bz2
libpatch-master.tar.xz
First commitHEADmaster
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'libpatch_append_to_patch__.c')
-rw-r--r--libpatch_append_to_patch__.c28
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;
+}