mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 03:00:34 +03:00
Merge branch 'feat/refactor_stdio_vfs_v6.1' into 'release/v6.1'
feat(storage/stdio): refactor stdio vfs (v6.1) See merge request espressif/esp-idf!48957
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2024-2026 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -138,32 +138,38 @@ void esp_reent_cleanup(void)
|
||||
* Initialize stdin, stdout, and stderr using static memory allocation.
|
||||
* Creating them with fopen() would call malloc() internally.
|
||||
*/
|
||||
static char write_buf[BUFSIZ];
|
||||
static char read_buf[BUFSIZ];
|
||||
static char in_buf[BUFSIZ];
|
||||
static char out_buf[BUFSIZ];
|
||||
static char err_buf[BUFSIZ];
|
||||
|
||||
static struct __file_bufio __stdin = FDEV_SETUP_BUFIO(0, read_buf, BUFSIZ, read, write, lseek, close, __SRD, 0);
|
||||
static struct __file_bufio __stdout = FDEV_SETUP_BUFIO(1, write_buf, BUFSIZ, read, write, lseek, close, __SWR, __BLBF);
|
||||
static struct __file_bufio __stdin = FDEV_SETUP_BUFIO(0, in_buf, BUFSIZ, read, write, lseek, close, __SRD, 0);
|
||||
static struct __file_bufio __stdout = FDEV_SETUP_BUFIO(1, out_buf, BUFSIZ, read, write, lseek, close, __SWR, __BLBF);
|
||||
static struct __file_bufio __stderr = FDEV_SETUP_BUFIO(2, err_buf, BUFSIZ, read, write, lseek, close, __SWR, __BLBF);
|
||||
|
||||
FILE *stdin = &__stdin.xfile.cfile.file;
|
||||
FILE *stdout = &__stdout.xfile.cfile.file;
|
||||
FILE *stderr = &__stdout.xfile.cfile.file;
|
||||
FILE *stderr = &__stderr.xfile.cfile.file;
|
||||
|
||||
#if CONFIG_LIBC_PICOLIBC_NEWLIB_COMPATIBILITY
|
||||
__thread FILE* tls_stdin = &__stdin.xfile.cfile.file;
|
||||
__thread FILE* tls_stdout = &__stdout.xfile.cfile.file;
|
||||
__thread FILE* tls_stderr = &__stdout.xfile.cfile.file;
|
||||
__thread FILE* tls_stderr = &__stderr.xfile.cfile.file;
|
||||
#endif
|
||||
|
||||
#if CONFIG_VFS_SUPPORT_IO
|
||||
void esp_libc_init_global_stdio(const char *stdio_dev)
|
||||
{
|
||||
int stdin_fd = open(stdio_dev, O_RDONLY);
|
||||
assert(stdin_fd > 0);
|
||||
assert(stdin_fd >= 0); // Should be 0
|
||||
__stdin.ptr = (void *)(intptr_t)(stdin_fd);
|
||||
|
||||
int stdout_fd = open(stdio_dev, O_WRONLY);
|
||||
assert(stdout_fd > 0);
|
||||
assert(stdout_fd >= 0); // Should be 1
|
||||
__stdout.ptr = (void *)(intptr_t)(stdout_fd);
|
||||
|
||||
int stderr_fd = open(stdio_dev, O_WRONLY);
|
||||
assert(stderr_fd >= 0); // Should be 2
|
||||
__stderr.ptr = (void *)(intptr_t)(stderr_fd);
|
||||
}
|
||||
#else /* CONFIG_VFS_SUPPORT_IO */
|
||||
void esp_libc_init_global_stdio(void)
|
||||
|
||||
Reference in New Issue
Block a user