1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-16 18:13:49 +01:00

Merge pull request #20872 from benpicco/stdio_null-frontend

core: add stdio.h to replace stdout functions with stdio_null
This commit is contained in:
benpicco 2025-04-01 15:30:08 +00:00 committed by GitHub
commit 85dc9be1c9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 90 additions and 9 deletions

70
core/include/stdio.h Normal file
View File

@ -0,0 +1,70 @@
/*
* 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 <benjamin.valentin@ml-pa.com>
*/
#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 perror
#undef putchar
#undef puts
#undef printf
#undef vprintf
#define perror(s) (void)s
#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 */
/** @} */

View File

@ -177,9 +177,11 @@ ssize_t write(int fd, const void *src, size_t count)
#endif #endif
} }
#ifndef MODULE_STDIO_NULL
void perror(const char *s) void perror(const char *s)
{ {
printf("%s: %s\n", s, strerror(errno)); printf("%s: %s\n", s, strerror(errno));
} }
#endif
/** @} */ /** @} */

View File

@ -226,18 +226,13 @@ ssize_t _native_writev(int fd, const struct iovec *iov, int iovcnt)
#if defined(__FreeBSD__) #if defined(__FreeBSD__)
#undef putchar #undef putchar
#endif #endif
#ifndef MODULE_STDIO_NULL
int putchar(int c) int putchar(int c)
{ {
char tmp = c; char tmp = c;
return _native_write(STDOUT_FILENO, &tmp, sizeof(tmp)); return _native_write(STDOUT_FILENO, &tmp, sizeof(tmp));
} }
int putc(int c, FILE *fp)
{
char tmp = c;
return _native_write(fileno(fp), &tmp, sizeof(tmp));
}
int puts(const char *s) int puts(const char *s)
{ {
int r; int r;
@ -245,6 +240,13 @@ int puts(const char *s)
putchar('\n'); putchar('\n');
return r; return r;
} }
#endif
int putc(int c, FILE *fp)
{
char tmp = c;
return _native_write(fileno(fp), &tmp, sizeof(tmp));
}
int fgetc(FILE *fp) int fgetc(FILE *fp)
{ {
@ -308,6 +310,7 @@ char *make_message(const char *format, va_list argp)
} }
} }
#ifndef MODULE_STDIO_NULL
int printf(const char *format, ...) int printf(const char *format, ...)
{ {
int r; int r;
@ -324,6 +327,7 @@ int vprintf(const char *format, va_list argp)
{ {
return vfprintf(stdout, format, argp); return vfprintf(stdout, format, argp);
} }
#endif
int fprintf(FILE *fp, const char *format, ...) int fprintf(FILE *fp, const char *format, ...)
{ {

View File

@ -43,6 +43,7 @@ def fix_headerguard(filename):
tmp.seek(0) tmp.seek(0)
guard_found = 0 guard_found = 0
include_next_found = 0
guard_name = "" guard_name = ""
ifstack = 0 ifstack = 0
for line in inlines: for line in inlines:
@ -66,11 +67,14 @@ def fix_headerguard(filename):
else: else:
guard_found += 1 guard_found += 1
line = "#endif /* %s */\n" % supposed line = "#endif /* %s */\n" % supposed
elif line.startswith("#include_next"):
include_next_found = 1
tmp.write(line) tmp.write(line)
tmp.seek(0) tmp.seek(0)
if guard_found == 3: if guard_found == 3:
if include_next_found == 0:
for line in difflib.unified_diff(inlines, tmp.readlines(), for line in difflib.unified_diff(inlines, tmp.readlines(),
"%s" % filename, "%s" % filename): "%s" % filename, "%s" % filename):
sys.stdout.write(line) sys.stdout.write(line)

View File

@ -13,6 +13,7 @@ JERRY_GC_LIMIT ?= 0 # Use default value, e.g. 1/32 of total heap size
JERRY_GC_MARK_LIMIT ?= 8 # maximum recursion depth during GC mark phase JERRY_GC_MARK_LIMIT ?= 8 # maximum recursion depth during GC mark phase
EXT_CFLAGS := -D__TARGET_RIOT EXT_CFLAGS := -D__TARGET_RIOT
EXT_CFLAGS += -Wno-pedantic
CFLAGS += -Wno-cast-align CFLAGS += -Wno-cast-align
# disable warnings when compiling with LLVM for board native # disable warnings when compiling with LLVM for board native