Commit timespec to file on Timespec.Add; Unlink timespec file on Timespec.Clear; Initialize timespec from file in channel_init()
This commit is contained in:
@ -274,6 +274,7 @@ bool timespec_write_file(struct mgos_timespec *ts, const char *fn) {
|
||||
}
|
||||
close(fd);
|
||||
|
||||
LOG(LL_INFO, ("Wrote timespec to %s", fn));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -294,13 +295,18 @@ bool timespec_read_file(struct mgos_timespec *ts, const char *fn) {
|
||||
|
||||
if (0 != stat(fn, &fp_stat)) {
|
||||
LOG(LL_ERROR, ("Could not stat %s", fn));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (fp_stat.st_size > 1024) {
|
||||
LOG(LL_ERROR, ("File size of %s is larger than 1024 bytes (%u)", fn, (uint32_t)fp_stat.st_size));
|
||||
return false;
|
||||
}
|
||||
|
||||
buf = malloc(fp_stat.st_size + 1);
|
||||
if (!buf) {
|
||||
LOG(LL_ERROR, ("Could not malloc %u bytes for file %s", (uint32_t)fp_stat.st_size, fn));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(fd = open(fn, O_RDONLY))) {
|
||||
@ -316,7 +322,6 @@ bool timespec_read_file(struct mgos_timespec *ts, const char *fn) {
|
||||
}
|
||||
buf[fp_stat.st_size] = '\0';
|
||||
close(fd);
|
||||
LOG(LL_INFO, ("buf='%s'", buf));
|
||||
|
||||
// Wipe the timespec and parse back
|
||||
timespec_clear_spec(ts);
|
||||
@ -328,5 +333,6 @@ bool timespec_read_file(struct mgos_timespec *ts, const char *fn) {
|
||||
}
|
||||
}
|
||||
free(buf);
|
||||
LOG(LL_INFO, ("Read timespec from %s", fn));
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user