summaryrefslogtreecommitdiffstats
path: root/liblog_init_context.c
blob: ff3f574ad4118f67ee3420665b22787543816c33 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* See LICENSE file for copyright and license details. */
#include "common.h"
#ifndef TEST

int
liblog_init_context(struct liblog_context *ctx)
{
	if (!ctx) {
		errno = EINVAL;
		return -1;
	}
	ctx->internal_state = NULL;
	ctx->outputs = NULL;
	ctx->noutputs = 0;
	ctx->logmask = 0;
	liblog_apply_env_mask(ctx);
	return 0;
}

#else

int
main(void)
{
	struct liblog_context ctx;
	char *nullenv[] = {NULL};

	environ = nullenv;

	errno = 0;
	ASSERT_EQ_INT(liblog_init_context(NULL), -1);
	ASSERT_EQ_INT(errno, EINVAL);

	ASSERT_ZERO(liblog_init_context(&ctx));
	ASSERT_IS_NULL(ctx.internal_state);
	ASSERT_IS_NULL(ctx.outputs);
	ASSERT_ZERO(ctx.noutputs);
	ASSERT_EQ_UINT(ctx.logmask, ((1U << 9) - 1U) ^ ((1U << ((int)LIBLOG_WARNING / LOGLEVEL_DELTA + 1)) - 1U));

	return 0;
}

#endif