From 29c45dc4348e7db61aa80ba1657cbc2d8b1a19ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 10 Oct 2022 09:18:26 +0200 Subject: man: use external .c files for three examples This way it's much easier to test that the code compiles without issues. It's also easier to edit the code. Indentation in one of the examples is reduced to two spaces. This is what we use in man pages to make them fit on screen better. --- man/journal-stream-fd.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 man/journal-stream-fd.c (limited to 'man/journal-stream-fd.c') diff --git a/man/journal-stream-fd.c b/man/journal-stream-fd.c new file mode 100644 index 0000000000..6bc5582189 --- /dev/null +++ b/man/journal-stream-fd.c @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: CC0-1.0 */ + +#include +#include +#include +#include +#include +#include + +int main(int argc, char *argv[]) { + int fd; + FILE *log; + fd = sd_journal_stream_fd("test", LOG_INFO, 1); + if (fd < 0) { + fprintf(stderr, "Failed to create stream fd: %s\n", strerror(-fd)); + return 1; + } + log = fdopen(fd, "w"); + if (!log) { + fprintf(stderr, "Failed to create file object: %m\n"); + close(fd); + return 1; + } + fprintf(log, "Hello World!\n"); + fprintf(log, SD_WARNING "This is a warning!\n"); + fclose(log); + return 0; +} -- cgit v1.2.1