diff options
| author | Markus Mittendrein <git@maxmitti.tk> | 2018-08-15 22:46:40 +0200 |
|---|---|---|
| committer | Markus Mittendrein <git@maxmitti.tk> | 2018-08-15 23:15:15 +0200 |
| commit | 0d1ae015fef8e15442dafa61b9c8d929ce467969 (patch) | |
| tree | a8d56fd12f5c5366e1f6fa3ecc20c78c0202f747 /src/c4groupheader.c | |
| parent | e04f662a42c75cb202684e7254d3b7600e6e1756 (diff) | |
| download | cc4group-0d1ae015fef8e15442dafa61b9c8d929ce467969.tar.gz cc4group-0d1ae015fef8e15442dafa61b9c8d929ce467969.zip | |
Refactor code into a library and implement basic file management methods
Diffstat (limited to 'src/c4groupheader.c')
| -rw-r--r-- | src/c4groupheader.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/c4groupheader.c b/src/c4groupheader.c new file mode 100644 index 0000000..e06155c --- /dev/null +++ b/src/c4groupheader.c @@ -0,0 +1,40 @@ +#include "c4groupheader.h" +#include <string.h> +#include <time.h> + +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; +} |
