From 1a6f9b807d2fad469035b25156cac94afda28751 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Mon, 22 Feb 2021 13:21:43 -0500 Subject: Move is_utf8_bom() to str.h This moves is_utf8_bom() to str.h, and also adds two #defines, UTF8_BOM and UTF8_BOM_SIZE. Signed-off-by: Peter Jones --- include/str.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'include') diff --git a/include/str.h b/include/str.h index 0c34256d..72f87b75 100644 --- a/include/str.h +++ b/include/str.h @@ -214,4 +214,15 @@ strntoken(char *str, size_t max, const char *delims, char **token, char *state) return state_is_delim; } +#define UTF8_BOM { 0xef, 0xbb, 0xbf } +#define UTF8_BOM_SIZE 3 + +static inline UNUSED NONNULL(1) BOOLEAN +is_utf8_bom(CHAR8 *buf, size_t bufsize) +{ + unsigned char bom[] = UTF8_BOM; + + return CompareMem(buf, bom, MIN(UTF8_BOM_SIZE, bufsize)) == 0; +} + #endif /* SHIM_STR_H */ -- cgit v1.2.3