2020-12-06 19:27:42 -05:00
|
|
|
#include <kernaux/printf.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
2022-01-19 07:01:21 -05:00
|
|
|
#include <stddef.h>
|
2020-12-06 19:27:42 -05:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#define BUFFER_SIZE 1024
|
|
|
|
|
|
|
|
static char buffer[BUFFER_SIZE];
|
2021-12-16 10:26:16 -05:00
|
|
|
static size_t buffer_index = 0;
|
2020-12-06 19:27:42 -05:00
|
|
|
|
|
|
|
static void my_putchar(const char chr)
|
|
|
|
{
|
|
|
|
if (buffer_index >= BUFFER_SIZE) abort();
|
|
|
|
buffer[buffer_index++] = chr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void my_printf(const char *const format, ...)
|
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
va_start(va, format);
|
2022-01-19 07:01:21 -05:00
|
|
|
kernaux_vprintf(my_putchar, NULL, format, va);
|
2020-12-06 19:27:42 -05:00
|
|
|
va_end(va);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
my_printf("Hello, %s! Session ID: %u.", "Alex", 123);
|
|
|
|
assert(strcmp(buffer, "Hello, Alex! Session ID: 123.") == 0);
|
|
|
|
return 0;
|
|
|
|
}
|