From 392a33d6c59b949d6264a3b438a38a4e3183eef2 Mon Sep 17 00:00:00 2001 From: armink Date: Fri, 12 Jan 2018 16:55:47 +0800 Subject: [PATCH] [libc] Add libc_stdio_get_console . --- components/libc/compilers/armlibc/libc.h | 1 + components/libc/compilers/armlibc/stdio.c | 5 +++++ components/libc/compilers/dlib/libc.h | 1 + components/libc/compilers/dlib/stdio.c | 4 ++++ components/libc/compilers/newlib/libc.h | 1 + components/libc/compilers/newlib/stdio.c | 7 +++++++ 6 files changed, 19 insertions(+) diff --git a/components/libc/compilers/armlibc/libc.h b/components/libc/compilers/armlibc/libc.h index aef0324018..e57897f0a8 100644 --- a/components/libc/compilers/armlibc/libc.h +++ b/components/libc/compilers/armlibc/libc.h @@ -31,6 +31,7 @@ int libc_system_init(void); int libc_stdio_set_console(const char* device_name, int mode); +int libc_stdio_get_console(void); int libc_stdio_read (void *buffer, size_t size); int libc_stdio_write(const void *buffer, size_t size); diff --git a/components/libc/compilers/armlibc/stdio.c b/components/libc/compilers/armlibc/stdio.c index cba51beb18..d1ac976568 100644 --- a/components/libc/compilers/armlibc/stdio.c +++ b/components/libc/compilers/armlibc/stdio.c @@ -58,6 +58,11 @@ int libc_stdio_set_console(const char* device_name, int mode) return std_fd; } +int libc_stdio_get_console(void) +{ + return std_fd; +} + int libc_stdio_read(void *buffer, size_t size) { return read(std_fd, buffer, size); diff --git a/components/libc/compilers/dlib/libc.h b/components/libc/compilers/dlib/libc.h index db571d2ee1..d0a081d538 100644 --- a/components/libc/compilers/dlib/libc.h +++ b/components/libc/compilers/dlib/libc.h @@ -32,6 +32,7 @@ int libc_system_init(void); int libc_stdio_set_console(const char* device_name, int mode); +int libc_stdio_get_console(void); int libc_stdio_read (void *buffer, size_t size); int libc_stdio_write(const void *buffer, size_t size); diff --git a/components/libc/compilers/dlib/stdio.c b/components/libc/compilers/dlib/stdio.c index 24e421f2b3..12c1081d8b 100644 --- a/components/libc/compilers/dlib/stdio.c +++ b/components/libc/compilers/dlib/stdio.c @@ -58,6 +58,10 @@ int libc_stdio_set_console(const char* device_name, int mode) return std_fd; } +int libc_stdio_get_console(void) { + return std_fd; +} + int libc_stdio_read(void *buffer, size_t size) { return read(std_fd, buffer, size); diff --git a/components/libc/compilers/newlib/libc.h b/components/libc/compilers/newlib/libc.h index 7cab52a11f..d077de9656 100644 --- a/components/libc/compilers/newlib/libc.h +++ b/components/libc/compilers/newlib/libc.h @@ -38,6 +38,7 @@ int libc_system_init(void); int libc_stdio_set_console(const char* device_name, int mode); +int libc_stdio_get_console(void); /* some time related function */ int libc_set_time(const struct timespec *time); diff --git a/components/libc/compilers/newlib/stdio.c b/components/libc/compilers/newlib/stdio.c index 276e68050c..f28383818d 100644 --- a/components/libc/compilers/newlib/stdio.c +++ b/components/libc/compilers/newlib/stdio.c @@ -83,3 +83,10 @@ int libc_stdio_set_console(const char* device_name, int mode) return fileno(std_console); } + +int libc_stdio_get_console(void) { + if (std_console) + return fileno(std_console); + else + return -1; +}