summaryrefslogtreecommitdiff
path: root/ds.h
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2025-02-19 16:50:31 -0500
committerpommicket <pommicket@gmail.com>2025-02-19 16:50:31 -0500
commitccb3ec86fc8cbfaa2e13c16e3c9952293670d564 (patch)
tree6976865674c747e3731eef4ec0d1a3d7c5114b26 /ds.h
parentae508d6b2d020649f9382fa54c56cda06acfd304 (diff)
code cleanup, remove broken usb identification
Diffstat (limited to 'ds.h')
-rw-r--r--ds.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/ds.h b/ds.h
index 1a3d771..2d23742 100644
--- a/ds.h
+++ b/ds.h
@@ -656,4 +656,28 @@ static void int_hash_table_clear(IntHashTable *t) {
t->count = 0;
}
+static char *va_sprintf(const char *fmt, va_list args) {
+ va_list args_copy;
+ va_copy(args_copy, args);
+ char fakebuf[2] = {0};
+ int ret = vsnprintf(fakebuf, 1, fmt, args_copy);
+ va_end(args_copy);
+
+ if (ret < 0) return NULL; // bad format or something
+ size_t n = (size_t)ret;
+ char *str = calloc(1, n + 1);
+ vsnprintf(str, n + 1, fmt, args);
+ return str;
+}
+
+static char *a_sprintf(PRINTF_FORMAT_STRING const char *fmt, ...) ATTRIBUTE_PRINTF(1, 2);
+static char *a_sprintf(const char *fmt, ...) {
+ // idk if you can always just pass NULL to vsnprintf
+ va_list args;
+ va_start(args, fmt);
+ char *str = va_sprintf(fmt, args);
+ va_end(args);
+ return str;
+}
+
#endif // DS_H_