crt: Add snprintf test

Signed-off-by: Martin Storsjö <martin@martin.st>
This commit is contained in:
Pali Rohár 2024-11-15 17:59:57 +01:00 committed by Martin Storsjö
parent 581532b8e4
commit 20bc9fa6f8
5 changed files with 26 additions and 0 deletions

View File

@ -4190,6 +4190,9 @@ testcase_progs = \
testcases/t_matherr \
testcases/t_nullptrexception \
testcases/t_readdir \
testcases/t_snprintf \
testcases/t_snprintf0 \
testcases/t_snprintf1 \
testcases/t_setjmp \
testcases/t_sigv \
testcases/t_speed_powl \

View File

@ -0,0 +1 @@
#include "t_snprintf_tmpl.h"

View File

@ -0,0 +1,2 @@
#define __USE_MINGW_ANSI_STDIO 0
#include "t_snprintf_tmpl.h"

View File

@ -0,0 +1,2 @@
#define __USE_MINGW_ANSI_STDIO 1
#include "t_snprintf_tmpl.h"

View File

@ -0,0 +1,18 @@
#include <stdio.h>
#include <string.h>
int main() {
int i;
char buffer[10] = "XXXXXXXXXX";
int ret = snprintf(buffer, 3, "%s", "AAA");
if (ret != 3 || memcmp(buffer, "AA\0XXXXXXX", 10) != 0) {
fprintf(stderr, "ret: expected=3 got=%d\n", ret);
fprintf(stderr, "buffer:");
for (i = 0; i < 10; i++) {
fprintf(stderr, " 0x%02x", (int)buffer[i]);
}
fprintf(stderr, "\n");
return 1;
}
return 0;
}