Skip to main content

restore_posix_stdio_fds

Function restore_posix_stdio_fds 

Source
pub fn restore_posix_stdio_fds() -> bool
Expand description

Restores the POSIX binding between the C standard streams and file descriptors 0, 1 and 2, so that reads from descriptor 0 and writes to descriptors 1 and 2 go to /dev/console.

Returns true if the binding is in place when the function returns (either because it was already in place, or because it was successfully restored), and false otherwise.

The function is idempotent. It is called automatically from the app_main glue of the binstart/libstart features, so calling it explicitly is only necessary with a custom app_main.

On ESP-IDF versions older than v5.3 the restoration is not attempted (the function only reports whether the binding happens to be in place): the console of those versions does not refcount its open/close calls, which the re-arrangement of the descriptors relies on. For the older versions, the CONFIG_ESP_CONSOLE_SECONDARY_NONE=y sdkconfig setting is a build-time alternative, as it results in descriptors 1 and 2 landing on the console.

NOTE: the standard streams are detached from the console and re-attached to it while the function runs, so it must be called before any other thread might be using them - which is why the app_main glue calls it first thing.