-
Notifications
You must be signed in to change notification settings - Fork 0
/
LinuxSeedFileManager.cpp
54 lines (46 loc) · 1002 Bytes
/
LinuxSeedFileManager.cpp
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
44
45
46
47
48
49
50
51
52
53
54
/*
* File: LinuxSeedFileManager.cpp
* Author: matt
*
* Created on 17 December 2014, 10:31
*/
#ifndef ARDUINO
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <ios>
#include "LinuxSeedFileManager.h"
LinuxSeedFileManager::LinuxSeedFileManager()
{
if(access(SEED_FILE,F_OK|R_OK|W_OK) == -1)
{
fTimeAccess = true;
FILE *file = fopen(SEED_FILE,"a");
fclose(file);
}
else
{
fTimeAccess = false;
}
}
uint8_t* LinuxSeedFileManager::readSeedFile()
{
if(fTimeAccess == true)
{
return NULL;
}
seedData = new uint8_t[SEED_FILE_SIZE];
FILE *file = fopen(SEED_FILE,"r");
fread(seedData,sizeof(uint8_t),SEED_FILE_SIZE, file);
fclose(file);
return seedData;
}
void LinuxSeedFileManager::writeSeedFile(uint8_t* seed)
{
fTimeAccess = false;
FILE *file = fopen(SEED_FILE,"w");
fwrite(seed,sizeof(uint8_t), SEED_FILE_SIZE, file);
fclose(file);
}
#endif