summaryrefslogtreecommitdiffstats
path: root/src/c4groupheader.c
blob: 12d454ee5d153b80ebb8605860060bd2641d0277 (plain)
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
#include "c4groupheader.h"
#include <string.h>
#include <time.h>
#include <assert.h>

static_assert(sizeof(C4GroupHeader) == 204, "The size of the C4GroupHeader struct must be 204");

void C4GroupHeader_init(C4GroupHeader* const this)
{
	// id is not cleared because the id string exactly fits the size
	strcpy(this->id, C4GroupId);
	memset(this->Reserved1, 0, sizeof(this->Reserved1));
	memset(this->Reserved2, 0, sizeof(this->Reserved2));
	memset(this->Password, 0, sizeof(this->Password));

	this->Ver1 = 1;
	this->Ver2 = 2;
	this->Entries = 0;
	C4GroupHeader_setMaker(this, "New C4Group");
	this->Maker[C4GroupMaxMaker + 1] = '\0';
	C4GroupHeader_setCreation(this, time(NULL));
	C4GroupHeader_setOfficial(this, false);
}

void C4GroupHeader_setMaker(C4GroupHeader* const this, const char* const maker)
{
	strncpy(this->Maker, maker, C4GroupMaxMaker + 1);
}

void C4GroupHeader_setCreation(C4GroupHeader* const this, int32_t const creation)
{
	this->Creation = creation;
}

void C4GroupHeader_setOfficial(C4GroupHeader* const this, const bool official)
{
	this->Official = official ? C4GroupOfficial : 0;
}

bool C4GroupHeader_isOfficial(const C4GroupHeader* const this)
{
	return this->Official == C4GroupOfficial;
}