summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author@syxhe <https://t.me/syxhe>2025-01-06 21:04:27 -0600
committer@syxhe <https://t.me/syxhe>2025-01-06 21:04:27 -0600
commit227bc3560762ae770564fcd8bad36b334696bb0b (patch)
tree4bbc6ffea7036e979a701b7107ab1ef41b97e55d /src
parentf8e94a1179633799579a09dce1841f41e3b73f05 (diff)
sdptiny
Diffstat (limited to 'src')
-rw-r--r--src/encryption.c7
-rw-r--r--src/shared.c26
-rw-r--r--src/shared.h6
3 files changed, 6 insertions, 33 deletions
diff --git a/src/encryption.c b/src/encryption.c
index e92e4e7..c74c07e 100644
--- a/src/encryption.c
+++ b/src/encryption.c
@@ -1,3 +1,5 @@
1#define _GNU_SOURCE
2
1#include "encryption.h" 3#include "encryption.h"
2#include "shared.h" 4#include "shared.h"
3 5
@@ -44,7 +46,10 @@ int maketmp(const char *dest, const char *format, ...) {
44int main() { 46int main() {
45 char *test = NULL; 47 char *test = NULL;
46 48
47 saprintf(&test, "We do a little trolling %d", 900); 49 // Turns out GNU did this for me, and I trust their code more than my own, so I'm using this now
50 if(asprintf(&test, "We do a little trolling %d", 900) < 0)
51 error(1, ENOMEM, "asprintf call failed");
52
48 printf("%s\n", test); 53 printf("%s\n", test);
49 54
50 return 0; 55 return 0;
diff --git a/src/shared.c b/src/shared.c
index 0c7c8e2..2beaeb8 100644
--- a/src/shared.c
+++ b/src/shared.c
@@ -34,29 +34,3 @@ void* xreallocarray(void *ptr, size_t nmemb, size_t size) {
34 34
35 return mem; 35 return mem;
36} 36}
37
38int vsaprintf(char **str, const char *format, va_list ap) {
39 va_list ap2;
40 va_copy(ap2, ap);
41
42 int length = vsnprintf(NULL, 0, format, ap2) + 1; // + 1 because sprintf does not count the null byte
43 char *temp = reallocarray(*str, length, sizeof(char));
44 if(temp == NULL)
45 return -1;
46
47 int ret = vsnprintf(temp, length, format, ap);
48 *str = temp;
49
50 va_end(ap2);
51 return ret;
52}
53
54int saprintf(char **str, const char *format, ...) {
55 va_list ap;
56 va_start(ap, format);
57
58 int ret = vsaprintf(str, format, ap);
59
60 va_end(ap);
61 return ret;
62} \ No newline at end of file
diff --git a/src/shared.h b/src/shared.h
index fef19ca..b10462e 100644
--- a/src/shared.h
+++ b/src/shared.h
@@ -15,10 +15,4 @@ void* xcalloc(size_t nmemb, size_t size);
15// `reallocarray()` with error checking. Calls `error()` or `abort()` on error, depending on the value of `___VXGG___XCALLOC_EXIT_ON_ERROR___` 15// `reallocarray()` with error checking. Calls `error()` or `abort()` on error, depending on the value of `___VXGG___XCALLOC_EXIT_ON_ERROR___`
16void* xreallocarray(void *ptr, size_t nmemb, size_t size); 16void* xreallocarray(void *ptr, size_t nmemb, size_t size);
17 17
18// `vsprintf()`, but reallocates enough room for the resulting string before writing to `str`
19int vsaprintf(char **str, const char *format, va_list ap);
20
21// `sprintf()`, but reallocates enough room for the resulting string before writing to `str`
22int saprintf(char **str, const char *format, ...);
23
24#endif \ No newline at end of file 18#endif \ No newline at end of file