stdio: Introduce a new helper stdio_file_to_flags()
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Thu, 11 Feb 2021 15:09:36 +0000 (17:09 +0200)
committerTom Rini <trini@konsulko.com>
Tue, 16 Feb 2021 16:16:07 +0000 (11:16 -0500)
Let's deduplicate existing copies by splitting off to a new helper.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
common/stdio.c
include/stdio_dev.h

index 61fc087..d4acc52 100644 (file)
@@ -28,6 +28,19 @@ static struct stdio_dev devs;
 struct stdio_dev *stdio_devices[] = { NULL, NULL, NULL };
 char *stdio_names[MAX_FILES] = { "stdin", "stdout", "stderr" };
 
+int stdio_file_to_flags(const int file)
+{
+       switch (file) {
+       case stdin:
+               return DEV_FLAGS_INPUT;
+       case stdout:
+       case stderr:
+               return DEV_FLAGS_OUTPUT;
+       default:
+               return -EINVAL;
+       }
+}
+
 #if CONFIG_IS_ENABLED(SYS_DEVICE_NULLDEV)
 static void nulldev_putc(struct stdio_dev *dev, const char c)
 {
index 109a68d..8fb9a12 100644 (file)
@@ -18,6 +18,8 @@
 #define DEV_FLAGS_OUTPUT 0x00000002    /* Device can be used as output console */
 #define DEV_FLAGS_DM     0x00000004    /* Device priv is a struct udevice * */
 
+int stdio_file_to_flags(const int file);
+
 /* Device information */
 struct stdio_dev {
        int     flags;                  /* Device flags: input/output/system    */