summaryrefslogtreecommitdiff
path: root/src/shared.c
diff options
context:
space:
mode:
author@syxhe <https://t.me/syxhe>2026-01-15 12:47:29 -0600
committer@syxhe <https://t.me/syxhe>2026-01-15 12:47:29 -0600
commit940bd53b5a6fc1864d6a57b16d7f1b4b594f1851 (patch)
treefc6d186e1cc1aa62040b0314d0aa8819f69b7042 /src/shared.c
parentc4b9503b3e3331c09712810910d2b36f52d98ada (diff)
Work on _cryptscan__crypt and related functionsHEADmaster
Diffstat (limited to 'src/shared.c')
-rw-r--r--src/shared.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/shared.c b/src/shared.c
index 4e3fa01..4fd8b33 100644
--- a/src/shared.c
+++ b/src/shared.c
@@ -64,12 +64,32 @@ void* VXGG_ALLOC(size_t size) {
64#define ERROR(status, errnum, format, ...) do {error((status), (errnum), (format)__VA_ARGS__); exit((status));} while (0) 64#define ERROR(status, errnum, format, ...) do {error((status), (errnum), (format)__VA_ARGS__); exit((status));} while (0)
65//! Spit out a warning using `error` 65//! Spit out a warning using `error`
66#define WARN(errnum, format, ...) do {error(0, (errnum), (format)__VA_ARGS__);} while (0) 66#define WARN(errnum, format, ...) do {error(0, (errnum), (format)__VA_ARGS__);} while (0)
67// TODO: gcc is yelling at me about these functions implicitly falling through. Not sure why 67/// TODO: gcc is yelling at me about these functions implicitly falling through. Not sure why
68 68
69typedef int (*gcallback)(void*); //!< Generic callback signature 69typedef int (*gcallback)(void*); //!< Generic callback signature
70typedef void (*fcallback)(void*); //!< free()-like callback signature 70typedef void (*fcallback)(void*); //!< free()-like callback signature
71 71
72/** 72/**
73 * @brief Safe strcat implementation
74 *
75 * @param str1 A string of characters to append. Must be non-null
76 * @param str2 A string of characters being appended. Must be non-null
77 * @retval (char*)[NULL, char*] A heap-allocated, null terminated string consisting of `str1 + str2`. Null on error
78 */
79char* vxgg_sstrcat(const char *const str1, const char *const str2) {
80 if(!str1 || !str2) return NULL;
81
82 size_t s1 = strlen(str1), s2 = strlen(str2);
83 char *res = VXGG_CALLOC(s1 + s2 + 1, sizeof(*res));
84 if(!res) return NULL;
85
86 memmove(res, str1, s1);
87 memmove(res + s1, str2, s2);
88 res[s1 + s2] = '\0';
89 return res;
90}
91
92/**
73 * @brief Read the entire contents of a file descriptor into a malloc()'ed buffer 93 * @brief Read the entire contents of a file descriptor into a malloc()'ed buffer
74 * 94 *
75 * @param str Pointer to a string. Will be replaced with the malloc()'ed string 95 * @param str Pointer to a string. Will be replaced with the malloc()'ed string