From 940bd53b5a6fc1864d6a57b16d7f1b4b594f1851 Mon Sep 17 00:00:00 2001 From: "@syxhe" Date: Thu, 15 Jan 2026 12:47:29 -0600 Subject: Work on _cryptscan__crypt and related functions --- src/shared.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src/shared.c') diff --git a/src/shared.c b/src/shared.c index 4e3fa01..4fd8b33 100644 --- a/src/shared.c +++ b/src/shared.c @@ -64,11 +64,31 @@ void* VXGG_ALLOC(size_t size) { #define ERROR(status, errnum, format, ...) do {error((status), (errnum), (format)__VA_ARGS__); exit((status));} while (0) //! Spit out a warning using `error` #define WARN(errnum, format, ...) do {error(0, (errnum), (format)__VA_ARGS__);} while (0) -// TODO: gcc is yelling at me about these functions implicitly falling through. Not sure why +/// TODO: gcc is yelling at me about these functions implicitly falling through. Not sure why typedef int (*gcallback)(void*); //!< Generic callback signature typedef void (*fcallback)(void*); //!< free()-like callback signature +/** + * @brief Safe strcat implementation + * + * @param str1 A string of characters to append. Must be non-null + * @param str2 A string of characters being appended. Must be non-null + * @retval (char*)[NULL, char*] A heap-allocated, null terminated string consisting of `str1 + str2`. Null on error + */ +char* vxgg_sstrcat(const char *const str1, const char *const str2) { + if(!str1 || !str2) return NULL; + + size_t s1 = strlen(str1), s2 = strlen(str2); + char *res = VXGG_CALLOC(s1 + s2 + 1, sizeof(*res)); + if(!res) return NULL; + + memmove(res, str1, s1); + memmove(res + s1, str2, s2); + res[s1 + s2] = '\0'; + return res; +} + /** * @brief Read the entire contents of a file descriptor into a malloc()'ed buffer * -- cgit v1.2.3