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:
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
|
#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
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|||||||
@ -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, ...)
|
||||||
{
|
{
|
||||||
|
|||||||
10
dist/tools/headerguards/headerguards.py
vendored
10
dist/tools/headerguards/headerguards.py
vendored
@ -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,14 +67,17 @@ 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:
|
||||||
for line in difflib.unified_diff(inlines, tmp.readlines(),
|
if include_next_found == 0:
|
||||||
"%s" % filename, "%s" % filename):
|
for line in difflib.unified_diff(inlines, tmp.readlines(),
|
||||||
sys.stdout.write(line)
|
"%s" % filename, "%s" % filename):
|
||||||
|
sys.stdout.write(line)
|
||||||
else:
|
else:
|
||||||
print("%s: no / broken header guard" % filename, file=sys.stderr)
|
print("%s: no / broken header guard" % filename, file=sys.stderr)
|
||||||
return False
|
return False
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user