mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-25 01:02:24 +00:00
Macro to make a ptrlen out of a string literal.
I'm quite surprised I haven't needed this for anything else yet. I suppose if I had it, I could have written most of my ptrlen_eq_strings in terms of it, and saved a lot of gratuitous runtime strlens.
This commit is contained in:
parent
a313048763
commit
ce0b672e78
6
misc.h
6
misc.h
@ -107,6 +107,12 @@ int string_length_for_printf(size_t);
|
|||||||
/* Derive two printf arguments from a ptrlen, suitable for "%.*s" */
|
/* Derive two printf arguments from a ptrlen, suitable for "%.*s" */
|
||||||
#define PTRLEN_PRINTF(pl) \
|
#define PTRLEN_PRINTF(pl) \
|
||||||
string_length_for_printf((pl).len), (const char *)(pl).ptr
|
string_length_for_printf((pl).len), (const char *)(pl).ptr
|
||||||
|
/* Make a ptrlen out of a compile-time string literal. We try to
|
||||||
|
* enforce that it _is_ a string literal by token-pasting "" on to it,
|
||||||
|
* which should provoke a compile error if it's any other kind of
|
||||||
|
* string. */
|
||||||
|
#define PTRLEN_LITERAL(stringlit) \
|
||||||
|
TYPECHECK("" stringlit "", make_ptrlen(stringlit, sizeof(stringlit)-1))
|
||||||
|
|
||||||
/* Wipe sensitive data out of memory that's about to be freed. Simpler
|
/* Wipe sensitive data out of memory that's about to be freed. Simpler
|
||||||
* than memset because we don't need the fill char parameter; also
|
* than memset because we don't need the fill char parameter; also
|
||||||
|
Loading…
Reference in New Issue
Block a user