blob: 3de721f06c7f141c94804e297e06644409fe7447 [file] [log] [blame]
AKASHI Takahiro077153e2020-10-29 13:47:46 +09001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * String functions
4 *
5 * Copyright (c) 2020 AKASHI Takahiro, Linaro Limited
6 */
7
8#include <common.h>
9#include <charset.h>
10
11/**
12 * efi_create_indexed_name - create a string name with an index
13 * @buffer: Buffer
14 * @name: Name string
15 * @index: Index
16 *
17 * Create a utf-16 string with @name, appending @index.
18 * For example, L"Capsule0001"
19 *
20 * The caller must ensure that the buffer has enough space for the resulting
21 * string including the trailing L'\0'.
22 *
23 * Return: A pointer to the next position after the created string
24 * in @buffer, or NULL otherwise
25 */
26u16 *efi_create_indexed_name(u16 *buffer, const char *name, unsigned int index)
27{
28 u16 *p = buffer;
29 char index_buf[5];
30
31 utf8_utf16_strcpy(&p, name);
32 sprintf(index_buf, "%04X", index);
33 utf8_utf16_strcpy(&p, index_buf);
34
35 return p;
36}