From 6a6dd5db5808f9cb5397e62070db2841ece2e7dd Mon Sep 17 00:00:00 2001 From: Amar Mahmutbegovic Date: Mon, 12 May 2025 22:26:38 +0200 Subject: [PATCH] clean build warnings --- Chapter07/error_handling/CMakeLists.txt | 1 + .../error_handling/app/src/main_assert.cpp | 4 +++- .../cstdlib_support/nosys_stubs.c | 21 +++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 Chapter07/error_handling/cstdlib_support/nosys_stubs.c diff --git a/Chapter07/error_handling/CMakeLists.txt b/Chapter07/error_handling/CMakeLists.txt index dbf1b83..bc3b6c6 100644 --- a/Chapter07/error_handling/CMakeLists.txt +++ b/Chapter07/error_handling/CMakeLists.txt @@ -115,6 +115,7 @@ add_executable( platform/src/system_stm32f0xx.c hal/uart/src/uart_stm32.cpp cstdlib_support/retarget.cpp + cstdlib_support/nosys_stubs.c ${MAIN_CPP_PATH}/${MAIN_CPP_FILE_NAME} ) diff --git a/Chapter07/error_handling/app/src/main_assert.cpp b/Chapter07/error_handling/app/src/main_assert.cpp index 9ae2827..6e587f1 100644 --- a/Chapter07/error_handling/app/src/main_assert.cpp +++ b/Chapter07/error_handling/app/src/main_assert.cpp @@ -42,7 +42,9 @@ int main() printf("Assert example\r\n"); - const option opt = uint8_to_option(3); + + // maybe_unused attribute will silence unused variable warning + [[maybe_unused]] const option opt = uint8_to_option(3); while(true) { diff --git a/Chapter07/error_handling/cstdlib_support/nosys_stubs.c b/Chapter07/error_handling/cstdlib_support/nosys_stubs.c new file mode 100644 index 0000000..f54173e --- /dev/null +++ b/Chapter07/error_handling/cstdlib_support/nosys_stubs.c @@ -0,0 +1,21 @@ +#include +#include +#include <_ansi.h> +#include + +/* Minimal implementation of _fstat_r */ +int _fstat_r(struct _reent *r, int file, struct stat *st) { + st->st_mode = S_IFCHR; /* Character device */ + return 0; +} + +/* Minimal implementation of _getpid_r */ +int _getpid_r(struct _reent *r) { + return 1; /* Return a dummy process ID */ +} + +/* Minimal implementation of _kill_r */ +int _kill_r(struct _reent *r, int pid, int sig) { + r->_errno = EINVAL; + return -1; /* Indicate failure */ +}