core-lightning/common/onionreply.c
Rusty Russell 4ffda340d3 check: make sure all files outside contrib/ include "config.h" first.
And turn "" includes into full-path (which makes it easier to put
config.h first, and finds some cases check-includes.sh missed
previously).

config.h sets _GNU_SOURCE which really needs to be done before any
'#includes': we mainly got away with it with glibc, but other platforms
like Alpine may have stricter requirements.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-12-06 10:05:39 +10:30

43 lines
1.1 KiB
C

#include "config.h"
#include <ccan/cast/cast.h>
#include <common/onionreply.h>
#include <common/utils.h>
#include <wire/wire.h>
void towire_onionreply(u8 **cursor, const struct onionreply *r)
{
towire_u16(cursor, tal_count(r->contents));
towire_u8_array(cursor, r->contents, tal_count(r->contents));
}
struct onionreply *fromwire_onionreply(const tal_t *ctx,
const u8 **cursor, size_t *max)
{
struct onionreply *r = tal(ctx, struct onionreply);
r->contents = fromwire_tal_arrn(r, cursor, max,
fromwire_u16(cursor, max));
if (!*cursor)
return tal_free(r);
return r;
}
struct onionreply *dup_onionreply(const tal_t *ctx,
const struct onionreply *r TAKES)
{
struct onionreply *n;
if (taken(r))
return cast_const(struct onionreply *, tal_steal(ctx, r));
n = tal(ctx, struct onionreply);
n->contents = tal_dup_talarr(n, u8, r->contents);
return n;
}
struct onionreply *new_onionreply(const tal_t *ctx, const u8 *contents TAKES)
{
struct onionreply *r = tal(ctx, struct onionreply);
r->contents = tal_dup_talarr(r, u8, contents);
return r;
}