зеркало из https://github.com/github/putty.git
testcrypt: refactor return_opt_foo functions.
There are already three tediously similar functions that wrap a NULL check around some existing function to return one or another kind of pointer, and I'm about to want to add another one. Make a macro so that it's easy to make more functions identical to these three.
This commit is contained in:
Родитель
4b8aad76f8
Коммит
4d0c2ca90f
33
testcrypt.c
33
testcrypt.c
|
@ -503,29 +503,18 @@ static void return_val_string_asciz(strbuf *out, char *s)
|
||||||
return_val_string(out, sb);
|
return_val_string(out, sb);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void return_opt_val_string_asciz(strbuf *out, char *s)
|
#define NULLABLE_RETURN_WRAPPER(type_name, c_type) \
|
||||||
{
|
static void return_opt_##type_name(strbuf *out, c_type ptr) \
|
||||||
if (!s)
|
{ \
|
||||||
strbuf_catf(out, "NULL\n");
|
if (!ptr) \
|
||||||
else
|
strbuf_catf(out, "NULL\n"); \
|
||||||
return_val_string_asciz(out, s);
|
else \
|
||||||
}
|
return_##type_name(out, ptr); \
|
||||||
|
}
|
||||||
|
|
||||||
static void return_opt_val_cipher(strbuf *out, ssh_cipher *c)
|
NULLABLE_RETURN_WRAPPER(val_string_asciz, char *)
|
||||||
{
|
NULLABLE_RETURN_WRAPPER(val_cipher, ssh_cipher *)
|
||||||
if (!c)
|
NULLABLE_RETURN_WRAPPER(val_hash, ssh_hash *)
|
||||||
strbuf_catf(out, "NULL\n");
|
|
||||||
else
|
|
||||||
return_val_cipher(out, c);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void return_opt_val_hash(strbuf *out, ssh_hash *h)
|
|
||||||
{
|
|
||||||
if (!h)
|
|
||||||
strbuf_catf(out, "NULL\n");
|
|
||||||
else
|
|
||||||
return_val_hash(out, h);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void handle_hello(BinarySource *in, strbuf *out)
|
static void handle_hello(BinarySource *in, strbuf *out)
|
||||||
{
|
{
|
||||||
|
|
Загрузка…
Ссылка в новой задаче