diff --git a/components/console/linenoise/linenoise.c b/components/console/linenoise/linenoise.c index 92fcab393d..357d2c2415 100644 --- a/components/console/linenoise/linenoise.c +++ b/components/console/linenoise/linenoise.c @@ -107,7 +107,11 @@ #include #include #include -#include +#if !CONFIG_IDF_TARGET_LINUX +// On Linux, we don't need __fbufsize (see comments below), and +// __fbufsize not available on MacOS (which is also considered "Linux" target) +#include // for __fbufsize +#endif #include #include #include @@ -216,9 +220,14 @@ bool linenoiseIsDumbMode(void) { } static void flushWrite(void) { +// On Linux, we set stdout to unbuffered mode to facilitate interaction with tools. +// Performance on Linux is not considered as critical as on chip targets. Additionally, +// MacOS does not have __fbufsize. +#if !CONFIG_IDF_TARGET_LINUX if (__fbufsize(stdout) > 0) { fflush(stdout); } +#endif fsync(fileno(stdout)); } diff --git a/components/freertos/FreeRTOS-Kernel/portable/linux/port_idf.c b/components/freertos/FreeRTOS-Kernel/portable/linux/port_idf.c index a8823df715..04ad59fdb8 100644 --- a/components/freertos/FreeRTOS-Kernel/portable/linux/port_idf.c +++ b/components/freertos/FreeRTOS-Kernel/portable/linux/port_idf.c @@ -50,9 +50,9 @@ static void main_task(void* args) int main(int argc, const char **argv) { - // This makes sure that stdio is flushed after each '\n' so that idf.py monitor - // reads the program output on time. - setvbuf(stdout, NULL, _IOLBF, 0); + // This makes sure that stdio is always syncronized so that idf.py monitor + // and other tools read text output on time. + setvbuf(stdout, NULL, _IONBF, 0); usleep(1000); BaseType_t res = xTaskCreatePinnedToCore(&main_task, "main",