string-helpers.c: add str_starts_with()

This commit is contained in:
Johan Malm 2024-08-20 17:59:46 +01:00 committed by Johan Malm
parent 5db953aa89
commit 2446c46069
5 changed files with 45 additions and 7 deletions

View file

@ -1419,12 +1419,6 @@ handle_pipemenu_timeout(void *_ctx)
return 0;
}
static bool
starts_with_less_than(const char *s)
{
return (s + strspn(s, " \t\r\n"))[0] == '<';
}
static int
handle_pipemenu_readable(int fd, uint32_t mask, void *_ctx)
{
@ -1468,7 +1462,7 @@ handle_pipemenu_readable(int fd, uint32_t mask, void *_ctx)
}
/* Guard against badly formed data such as binary input */
if (!starts_with_less_than(ctx->buf.data)) {
if (!str_starts_with(ctx->buf.data, '<', " \t\r\n")) {
wlr_log(WLR_ERROR, "expect xml data to start with '<'; abort pipemenu");
goto clean_up;
}