Skip to content

Commit

Permalink
core: add stdio.h to replace stdout functions with stdio_null
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed Oct 1, 2024
1 parent 4b36bb6 commit 2d8d952
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions core/include/stdio.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright (C) 2024 ML!PA Consulting GmbH
*
* This file is subject to the terms and conditions of the GNU Lesser General
* Public License v2.1. See the file LICENSE in the top level directory for more
* details.
*/

/**
* @ingroup sys_stdio_null
*
* This module a wrapper for the stdio.h header intended to remove all calls
* to stdout when stdio_null is used.
*
* This needs to reside in `core/` so it gets included early.
*
* @{
*
* @file
* @brief stdio wrapper to replace the C libs stdio
*
* @author Benjamin Valentin <[email protected]>
*/

#ifndef CORE_STDIO_H
#define CORE_STDIO_H
#include_next "stdio.h"

#ifdef MODULE_STDIO_NULL

#include <stdarg.h>

#ifdef __cplusplus
extern "C"
{
#endif

static inline int printf_null(const char *restrict format, ...)
{
(void)format;
return 0;
}

static inline int vprintf_null(const char *restrict format, va_list ap)
{
(void)format;
(void)ap;
return 0;
}

#undef putchar
#undef puts
#undef printf
#undef vprintf

#define puts(s) (void)s
#define putchar(c) (void)c
#define printf(...) printf_null(__VA_ARGS__)
#define vprintf(format, ap) vprintf_null(format, ap)

#ifdef __cplusplus
}
#endif

#endif /* MODULE_STDIO_NULL */

#endif /* CORE_STDIO_H */
/** @} */

0 comments on commit 2d8d952

Please sign in to comment.