mirror of
https://github.com/tailix/libkernaux.git
synced 2024-11-27 11:14:42 -05:00
Add example for <kernaux/printf.h>
This commit is contained in:
parent
e7d355f950
commit
d3f6951dbe
3 changed files with 32 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -33,6 +33,7 @@
|
|||
/tests/test*.trs
|
||||
|
||||
/examples/cmdline
|
||||
/examples/printf
|
||||
/tests/multiboot2_print1
|
||||
/tests/multiboot2_print2
|
||||
/tests/test_cmdline
|
||||
|
|
|
@ -10,6 +10,7 @@ AM_CFLAGS = \
|
|||
lib_LIBRARIES = libkernaux.a
|
||||
|
||||
TESTS = \
|
||||
examples/printf \
|
||||
tests/test_printf \
|
||||
tests/test_stdlib
|
||||
|
||||
|
@ -57,6 +58,10 @@ examples_cmdline_SOURCES = \
|
|||
$(libkernaux_a_SOURCES) \
|
||||
examples/cmdline.c
|
||||
|
||||
examples_printf_SOURCES = \
|
||||
$(libkernaux_a_SOURCES) \
|
||||
examples/printf.c
|
||||
|
||||
tests_multiboot2_print1_SOURCES = \
|
||||
$(libkernaux_a_SOURCES) \
|
||||
tests/multiboot2_print1.c
|
||||
|
|
26
examples/printf.c
Normal file
26
examples/printf.c
Normal file
|
@ -0,0 +1,26 @@
|
|||
#include <kernaux/printf.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define BUFFER_SIZE 1024
|
||||
|
||||
static char buffer[BUFFER_SIZE];
|
||||
static unsigned int buffer_index;
|
||||
|
||||
static void my_putchar(const char chr)
|
||||
{
|
||||
if (buffer_index >= BUFFER_SIZE) abort();
|
||||
buffer[buffer_index++] = chr;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
memset(buffer, '\0', sizeof(buffer));
|
||||
buffer_index = 0;
|
||||
kernaux_printf(my_putchar, "Hello, World!");
|
||||
assert(strcmp(buffer, "Hello, World!") == 0);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue