diff --git a/components/newlib/syscalls.c b/components/newlib/syscalls.c index 06e342407c..e5e1f24a0b 100644 --- a/components/newlib/syscalls.c +++ b/components/newlib/syscalls.c @@ -73,6 +73,22 @@ static ssize_t _fstat_r_console(struct _reent *r, int fd, struct stat * st) return -1; } +static int _fsync_console(int fd) +{ + if (fd == STDOUT_FILENO || fd == STDERR_FILENO) { +#ifdef CONFIG_ESP_CONSOLE_UART + esp_rom_uart_flush_tx(CONFIG_ESP_CONSOLE_UART_NUM); +#elif defined(CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG) + esp_rom_uart_flush_tx(CONFIG_ESP_ROM_USB_SERIAL_DEVICE_NUM); +#elif defined(CONFIG_ESP_CONSOLE_USB_CDC) + esp_rom_uart_flush_tx(CONFIG_ESP_ROM_USB_OTG_NUM); +#endif + return 0; + } + errno = EBADF; + return -1; +} + /* The following weak definitions of syscalls will be used unless * another definition is provided. That definition may come from @@ -84,6 +100,8 @@ ssize_t _write_r(struct _reent *r, int fd, const void * data, size_t size) __attribute__((weak,alias("_write_r_console"))); int _fstat_r (struct _reent *r, int fd, struct stat *st) __attribute__((weak,alias("_fstat_r_console"))); +int fsync(int fd) + __attribute__((weak,alias("_fsync_console"))); /* The aliases below are to "syscall_not_implemented", which diff --git a/tools/test_apps/system/panic/main/test_panic.c b/tools/test_apps/system/panic/main/test_panic.c index 10d9f9e5a8..19f200ad76 100644 --- a/tools/test_apps/system/panic/main/test_panic.c +++ b/tools/test_apps/system/panic/main/test_panic.c @@ -27,6 +27,7 @@ void die(const char* msg) { printf("Test error: %s\n\n", msg); fflush(stdout); + fsync(fileno(stdout)); usleep(1000); /* Don't use abort here as it would enter the panic handler */ esp_restart_noos();