From: equilet <2237372+equilet@users.noreply.github.com> Date: Wed, 31 May 2023 16:56:29 +0000 (-0400) Subject: adding external append to handle header - single function X-Git-Tag: v0.1~33 X-Git-Url: https://git.dabkitsch.com/?a=commitdiff_plain;h=0782ed43198d24b13465f98efc47c98e736c0bcb;p=morphograph.git adding external append to handle header - single function --- diff --git a/source/ext_appendtohandle.h b/source/ext_appendtohandle.h new file mode 100644 index 0000000..b386545 --- /dev/null +++ b/source/ext_appendtohandle.h @@ -0,0 +1,30 @@ +// ext_appendtohandle.h +// +// Created by Jeff Lubow on 5/31/23 +// code from Jeremy Bernstein (c74) + +#ifndef ext_appendtohandle_h +#define ext_appendtohandle_h + +t_max_err my_sysmem_appendtextptrtohand(char *text, t_handle h) +{ + t_ptr_size i, oldsize, size; + char fudge = 0; + t_max_err rv = -1; + char *dst; + + if (text && h) { + size = strlen(text) + 1; // ensure zero termination + oldsize = sysmem_handlesize(h); + if (oldsize && !(*h)[oldsize - 1]) + fudge = 1; + if (!(rv = sysmem_resizehandle(h, oldsize + size - fudge))) { + dst = (*h) + oldsize - fudge; + for (i = 0; i < size; i++, dst++) + *dst = text[i]; + } + } + return rv; +} + +#endif /* ext_appendtohandle_h */