comparison test_asprintf.c @ 0:e3088565a6b8 default tip

*: initial commit kinda dumb, but wifi was out and I was bored. most of this code is shit.
author Paper <paper@tflc.us>
date Wed, 03 Dec 2025 03:04:39 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e3088565a6b8
1 #include "printf.h"
2
3 #include <stdint.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <limits.h>
7 #include <float.h>
8
9 int test_asprintf(void)
10 {
11 int n, n2;
12 char *s1, *s2;
13
14 n = my_asprintf(&s1,
15 #include "test.h"
16 );
17 if (n < 0) {
18 fprintf(stderr, "my_asprintf: %s\n", my_strerror(n));
19 return -1;
20 }
21 n2 = asprintf(&s2,
22 #include "test.h"
23 );
24 if (n2 < 0) {
25 my_free(s1);
26 perror("asprintf");
27 return -1;
28 }
29
30 if (strcmp(s1, s2) || (n != n2)) {
31 fprintf(stderr, "Got different results!!\n");
32 fprintf(stderr, " fprintf: %d; %s", n, s1);
33 fprintf(stderr, " my_fprintf: %d; %s", n2, s2);
34
35 my_free(s1);
36 free(s2);
37
38 return -1;
39 }
40
41 my_free(s1);
42 free(s2);
43
44 return 0;
45 }