mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-16 10:03:50 +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:
commit
85dc9be1c9
70
core/include/stdio.h
Normal file
70
core/include/stdio.h
Normal 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 */
|
||||
/** @} */
|
||||
@ -177,9 +177,11 @@ ssize_t write(int fd, const void *src, size_t count)
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef MODULE_STDIO_NULL
|
||||
void perror(const char *s)
|
||||
{
|
||||
printf("%s: %s\n", s, strerror(errno));
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
@ -226,18 +226,13 @@ ssize_t _native_writev(int fd, const struct iovec *iov, int iovcnt)
|
||||
#if defined(__FreeBSD__)
|
||||
#undef putchar
|
||||
#endif
|
||||
#ifndef MODULE_STDIO_NULL
|
||||
int putchar(int c)
|
||||
{
|
||||
char tmp = c;
|
||||
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 r;
|
||||
@ -245,6 +240,13 @@ int puts(const char *s)
|
||||
putchar('\n');
|
||||
return r;
|
||||
}
|
||||
#endif
|
||||
|
||||
int putc(int c, FILE *fp)
|
||||
{
|
||||
char tmp = c;
|
||||
return _native_write(fileno(fp), &tmp, sizeof(tmp));
|
||||
}
|
||||
|
||||
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 r;
|
||||
@ -324,6 +327,7 @@ int vprintf(const char *format, va_list argp)
|
||||
{
|
||||
return vfprintf(stdout, format, argp);
|
||||
}
|
||||
#endif
|
||||
|
||||
int fprintf(FILE *fp, const char *format, ...)
|
||||
{
|
||||
|
||||
4
dist/tools/headerguards/headerguards.py
vendored
4
dist/tools/headerguards/headerguards.py
vendored
@ -43,6 +43,7 @@ def fix_headerguard(filename):
|
||||
tmp.seek(0)
|
||||
|
||||
guard_found = 0
|
||||
include_next_found = 0
|
||||
guard_name = ""
|
||||
ifstack = 0
|
||||
for line in inlines:
|
||||
@ -66,11 +67,14 @@ def fix_headerguard(filename):
|
||||
else:
|
||||
guard_found += 1
|
||||
line = "#endif /* %s */\n" % supposed
|
||||
elif line.startswith("#include_next"):
|
||||
include_next_found = 1
|
||||
|
||||
tmp.write(line)
|
||||
|
||||
tmp.seek(0)
|
||||
if guard_found == 3:
|
||||
if include_next_found == 0:
|
||||
for line in difflib.unified_diff(inlines, tmp.readlines(),
|
||||
"%s" % filename, "%s" % filename):
|
||||
sys.stdout.write(line)
|
||||
|
||||
@ -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
|
||||
|
||||
EXT_CFLAGS := -D__TARGET_RIOT
|
||||
EXT_CFLAGS += -Wno-pedantic
|
||||
CFLAGS += -Wno-cast-align
|
||||
|
||||
# disable warnings when compiling with LLVM for board native
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user