mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-15 01:57:40 -05:00
A few new minor utility functions.
A function to compare two strings _both_ in ptrlen form (I've had ptrlen_eq_string for ages, but for some reason, never quite needed ptrlen_eq_ptrlen). A function to ask whether one ptrlen starts with another (and, optionally, return a ptrlen giving the remaining part of the longer string). And the va_list version of logeventf, which I really ought to have written in the first place by sheer habit, even if it was only needed by logeventf itself.
This commit is contained in:
18
misc.c
18
misc.c
@ -1259,6 +1259,24 @@ int ptrlen_eq_string(ptrlen pl, const char *str)
|
||||
return (pl.len == len && !memcmp(pl.ptr, str, len));
|
||||
}
|
||||
|
||||
int ptrlen_eq_ptrlen(ptrlen pl1, ptrlen pl2)
|
||||
{
|
||||
return (pl1.len == pl2.len && !memcmp(pl1.ptr, pl2.ptr, pl1.len));
|
||||
}
|
||||
|
||||
int ptrlen_startswith(ptrlen whole, ptrlen prefix, ptrlen *tail)
|
||||
{
|
||||
if (whole.len >= prefix.len &&
|
||||
!memcmp(whole.ptr, prefix.ptr, prefix.len)) {
|
||||
if (tail) {
|
||||
tail->ptr = (const char *)whole.ptr + prefix.len;
|
||||
tail->len = whole.len - prefix.len;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
char *mkstr(ptrlen pl)
|
||||
{
|
||||
char *p = snewn(pl.len + 1, char);
|
||||
|
Reference in New Issue
Block a user