fdt: Remove duplicate code
[oweals/u-boot.git] / lib / charset.c
index 0cede9b60b4ccdc0bc9cc28f4c3cbee0b9d77dc6..5e349ed5ee45248a8183accf806bb23ecabb8f94 100644 (file)
@@ -97,12 +97,17 @@ static u8 read_string(void *data)
 /**
  * read_console() - read byte from console
  *
- * @src                - not used, needed to match interface
- * Return:     - byte read
+ * @data       - not used, needed to match interface
+ * Return:     - byte read or 0 on error
  */
 static u8 read_console(void *data)
 {
-       return getc();
+       int ch;
+
+       ch = getc();
+       if (ch < 0)
+               ch = 0;
+       return ch;
 }
 
 int console_read_unicode(s32 *code)
@@ -344,6 +349,35 @@ size_t u16_strnlen(const u16 *in, size_t count)
        return i;
 }
 
+u16 *u16_strcpy(u16 *dest, const u16 *src)
+{
+       u16 *tmp = dest;
+
+       for (;; dest++, src++) {
+               *dest = *src;
+               if (!*src)
+                       break;
+       }
+
+       return tmp;
+}
+
+u16 *u16_strdup(const u16 *src)
+{
+       u16 *new;
+
+       if (!src)
+               return NULL;
+
+       new = malloc((u16_strlen(src) + 1) * sizeof(u16));
+       if (!new)
+               return NULL;
+
+       u16_strcpy(new, src);
+
+       return new;
+}
+
 /* Convert UTF-16 to UTF-8.  */
 uint8_t *utf16_to_utf8(uint8_t *dest, const uint16_t *src, size_t size)
 {