From de18565e2a1449760bc2d8dee956a842a26261a0 Mon Sep 17 00:00:00 2001 From: Ilya Tagunov Date: Tue, 12 Nov 2024 16:43:49 +0000 Subject: [PATCH] lib: libc: arcmwdt: replace the fileno macro The fileno macro defined in ARC MWDT headers conflicts with the fileno() function defined in lib/posix/options/device_io.c. We should undefine it and replace with a POSIX-compliant declaration and a weak definition. Signed-off-by: Ilya Tagunov --- lib/libc/arcmwdt/include/stdio.h | 26 ++++++++++++++++++++++++++ lib/libc/arcmwdt/libc-hooks.c | 7 +++++++ 2 files changed, 33 insertions(+) create mode 100644 lib/libc/arcmwdt/include/stdio.h diff --git a/lib/libc/arcmwdt/include/stdio.h b/lib/libc/arcmwdt/include/stdio.h new file mode 100644 index 00000000000..c062637d3b2 --- /dev/null +++ b/lib/libc/arcmwdt/include/stdio.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 Synopsys + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef LIB_LIBC_ARCMWDT_INCLUDE_STDIO_H_ +#define LIB_LIBC_ARCMWDT_INCLUDE_STDIO_H_ + +#include_next + +#ifdef fileno +#undef fileno +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +extern int fileno(FILE *file); + +#ifdef __cplusplus +} +#endif + +#endif /* LIB_LIBC_ARCMWDT_INCLUDE_STDIO_H_ */ diff --git a/lib/libc/arcmwdt/libc-hooks.c b/lib/libc/arcmwdt/libc-hooks.c index 8e094d25975..60ff32fb744 100644 --- a/lib/libc/arcmwdt/libc-hooks.c +++ b/lib/libc/arcmwdt/libc-hooks.c @@ -71,6 +71,13 @@ int _write(int fd, const char *buf, unsigned int nbytes) } #endif +#ifndef CONFIG_POSIX_DEVICE_IO +__weak int fileno(FILE *file) +{ + return _fileno(file); +} +#endif + /* * It's require to implement _isatty to have STDIN/STDOUT/STDERR buffered * properly.