2022-06-25 15:43:18 +00:00
|
|
|
#define KERNAUX_ACCESS_PROTECTED
|
|
|
|
|
|
|
|
#include <kernaux/generic/file.h>
|
2020-12-06 22:24:43 +00:00
|
|
|
#include <kernaux/printf.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
2022-01-19 12:01:21 +00:00
|
|
|
#include <stddef.h>
|
2020-12-06 22:24:43 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#define BUFFER_SIZE 1024
|
|
|
|
|
|
|
|
static char buffer[BUFFER_SIZE];
|
2021-12-16 15:26:16 +00:00
|
|
|
static size_t buffer_index = 0;
|
2020-12-06 22:24:43 +00:00
|
|
|
|
2022-06-25 15:43:18 +00:00
|
|
|
static int my_putc(__attribute__((unused)) void *const file, unsigned char c)
|
2020-12-06 22:24:43 +00:00
|
|
|
{
|
|
|
|
if (buffer_index >= BUFFER_SIZE) abort();
|
2022-06-25 15:43:18 +00:00
|
|
|
buffer[buffer_index++] = c;
|
|
|
|
return 1;
|
2020-12-06 22:24:43 +00:00
|
|
|
}
|
|
|
|
|
2022-06-25 15:43:18 +00:00
|
|
|
static const struct KernAux_File file = {
|
|
|
|
.putc = my_putc,
|
|
|
|
.puts = NULL,
|
|
|
|
.write = NULL,
|
|
|
|
};
|
|
|
|
|
2022-06-16 17:35:09 +00:00
|
|
|
void example_main()
|
2020-12-06 22:24:43 +00:00
|
|
|
{
|
2022-06-07 16:24:11 +00:00
|
|
|
const int result = kernaux_fprintf(
|
2022-06-07 18:08:47 +00:00
|
|
|
&file,
|
2022-01-20 11:58:08 +00:00
|
|
|
"Hello, %s! Session ID: %u.",
|
|
|
|
"Alex",
|
|
|
|
123
|
|
|
|
);
|
|
|
|
assert((size_t)result == strlen(buffer));
|
2020-12-07 00:22:52 +00:00
|
|
|
assert(strcmp(buffer, "Hello, Alex! Session ID: 123.") == 0);
|
2020-12-06 22:24:43 +00:00
|
|
|
}
|