
Implement stdio_get_fd() and stdio_set_fd() calls to access currently assigned STDIO devices. This will in turn allow to make the stdio_devices[] local to stdio.c
Signed-off-by: Marek Vasut marex@denx.de Cc: Wolfgang Denk wd@denx.de --- common/stdio.c | 26 ++++++++++++++++++++++++++ include/stdio_dev.h | 2 ++ 2 files changed, 28 insertions(+)
diff --git a/common/stdio.c b/common/stdio.c index 1bf9ba0..6c8ac73 100644 --- a/common/stdio.c +++ b/common/stdio.c @@ -33,6 +33,7 @@ #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C) #include <i2c.h> #endif +#include <errno.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -122,6 +123,31 @@ struct stdio_dev* stdio_get_by_name(const char *name) return NULL; }
+struct stdio_dev *stdio_get_fd(int ioe) +{ + switch (ioe) { + case stdin: + case stdout: + case stderr: + return stdio_devices[ioe]; + default: + return NULL; + } +} + +int stdio_set_fd(int ioe, struct stdio_dev *dev) +{ + switch (ioe) { + case stdin: + case stdout: + case stderr: + stdio_devices[ioe] = dev; + return 0; + default: + return -EINVAL; + } +} + struct stdio_dev* stdio_clone(struct stdio_dev *dev) { struct stdio_dev *_dev; diff --git a/include/stdio_dev.h b/include/stdio_dev.h index 23e0ee1..86b2a4f 100644 --- a/include/stdio_dev.h +++ b/include/stdio_dev.h @@ -97,6 +97,8 @@ int stdio_deregister(const char *devname); #endif struct list_head* stdio_get_list(void); struct stdio_dev* stdio_get_by_name(const char* name); +struct stdio_dev *stdio_get_fd(int ioe); +int stdio_set_fd(int ioe, struct stdio_dev *dev); struct stdio_dev* stdio_clone(struct stdio_dev *dev);
#ifdef CONFIG_ARM_DCC_MULTI