summaryrefslogtreecommitdiff
path: root/lib/charset.c
AgeCommit message (Collapse)Author
2023-01-04lib: add function u16_strcasecmp()Heinrich Schuchardt
Provide a function for comparing UTF-16 strings in a case insensitive manner. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2022-05-03lib/charset: add u16_strlcat() functionMasahisa Kojima
Provide u16 string version of strlcat(). Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org> Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2022-04-15lib: simplify u16_strdup()Heinrich Schuchardt
Use u16_strsize() instead of duplicating it. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2022-04-15lib: convert u16_strlen() into a macroHeinrich Schuchardt
The function u16_strlen() can be implemented as call to u16_strnlen(). Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2021-03-07lib/charset: UTF-8 stream conversionHeinrich Schuchardt
Provide functions to convert an UTF-8 stream to code page 437 or UTF-32. Add unit tests. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2021-03-07lib/charset: utf8_get() should return errorHeinrich Schuchardt
utf8_get() should return an error if hitting an illegal UTF-8 sequence and not silently convert the input to a question mark. Correct utf_8() and the its unit test. console_read_unicode() now will ignore illegal UTF-8 sequences. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2021-03-07efi_loader: carve out utf_to_cp()Heinrich Schuchardt
Carve out a function to translate a Unicode code point to an 8bit codepage. Provide a unit test for the new function. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2021-03-07efi_loader: move codepage 437 tableHeinrich Schuchardt
Move the Unicode to codepage 437 table to charset.c Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-11-29charset: make u16_strnlen accessible at runtimeIlias Apalodimas
commit 1fabfeef506c ("efi_loader: parameter check in GetNextVariableName()") introduces a check using u16_strnlen(). This code is used on EFI runtime variables as well, so unless we mark it as runtime, the kernel will crash trying to access it. Fixes: 1fabfeef506c ("efi_loader: parameter check in GetNextVariableName()") Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-10-22common: rename getc() to getchar()Heinrich Schuchardt
The sandbox is built with the SDL2 library with invokes the X11 library which in turn calls getc(). But getc() in glibc is defined as int getc(FILE *) This does not match our definition. int getc(void) The sandbox crashes when called with parameter -l. Rename our library symbol getc() to getchar(). Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Tom Rini <trini@konsulko.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2020-05-09charset: Add support for calculating bytes occupied by a u16 stringSughosh Ganu
The current code uses 'u16_strlen(x) + 1) * sizeof(u16)' in various places to calculate the number of bytes occupied by a u16 string. Let's introduce a wrapper around this. This wrapper is used on following patches Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-09-20lib: charset: add u16_str<n>cmp()AKASHI Takahiro
u16 version of strcmp(): u16_strncmp() works like u16_strcmp() but only at most n characters (in u16) are compared. This function will be used in my UEFI secure boot patch. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-07-16efi_loader: support unaligned u16 stringsHeinrich Schuchardt
Allow unaligned u16 strings as arguments to u16_strdup() and u16_strlen(). Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-02-13lib: add u16_strcpy/strdup functionsAkashi, Takahiro
Add u16_strcpy() and u16_strdup(). The latter function will be used later in implementing efi HII database protocol. Signed-off-by: Akashi Takahiro <takahiro.akashi@linaro.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
2018-10-16efi_loader: error handling in read_console()Heinrich Schuchardt
getc() might return an error code. Avoid an incorrect converison to Unicode. This addresses CoverityScan CID 184087. Reported-by: Tom Rini <trini@konsulko.com> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
2018-09-23efi_loader: support Unicode text inputHeinrich Schuchardt
Up to now the EFI_TEXT_INPUT_PROTOCOL only supported ASCII characters. With the patch it can consume UTF-8 from the console. Currently only the serial console and the console can deliver UTF-8. Local consoles are restricted to ASCII. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
2018-09-23lib: charset: upper/lower case conversionHeinrich Schuchardt
Provide functions for upper and lower case conversion. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
2018-09-23lib: charset: remove obsolete functionsHeinrich Schuchardt
Remove functions: - utf8_to_utf16() - utf16_strcpy() - utf16_strdup() Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
2018-09-23lib: charset: utility functions for UnicodeHeinrich Schuchardt
utf8_get() - get next UTF-8 code point from buffer utf8_put() - write UTF-8 code point to buffer utf8_utf16_strnlen() - length of a utf-8 string after conversion to utf-16 utf8_utf16_strncpy() - copy a utf-8 string to utf-16 utf16_get() - get next UTF-16 code point from buffer utf16_put() - write UTF-16 code point to buffer utf16_strnlen() - number of codes points in a utf-16 string utf16_utf8_strnlen() - length of a utf-16 string after conversion to utf-8 utf16_utf8_strncpy() - copy a utf-16 string to utf-8 Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
2018-09-23efi_loader: rename utf16_strlen, utf16_strnlenHeinrich Schuchardt
The function names utf16_strlen() and utf16_strnlen() are misnomers. The functions do not count utf-16 characters but non-zero words. So let's rename them to u16_strlen and u16_strnlen(). In utf16_dup() avoid assignment in if clause. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
2018-05-10SPDX: Convert a few files that were missed beforeTom Rini
As part of the main conversion a few files were missed. These files had additional whitespace after the '*' and before the SPDX tag and my previous regex was too strict. This time I did a grep for all SPDX tags and then filtered out anything that matched the correct styles. Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style") Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de> Signed-off-by: Tom Rini <trini@konsulko.com>
2017-12-01efi_loader: new function utf8_to_utf16Heinrich Schuchardt
Provide a conversion function from utf8 to utf16. Add missing #include <linux/types.h> in include/charset.h. Remove superfluous #include <common.h> in lib/charset.c. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
2017-09-12lib: add some utf16 handling helpersRob Clark
We'll eventually want these in a few places in efi_loader, and also vsprintf. Signed-off-by: Rob Clark <robdclark@gmail.com>