diff options
author | Chris <krzysztof.hockuba@trackener.com> | 2018-09-26 15:04:38 +0300 |
---|---|---|
committer | Christopher Haster <chaster@utexas.edu> | 2018-09-27 02:24:58 +0300 |
commit | 6ad544f3f3dde82e0faf1abacf50facc37086d88 (patch) | |
tree | aa35e7daad0c7e21752fd8f6fc14907cfd451cde /emubd | |
parent | 3419284689ead61c6905d61359a2b62a8c09c75d (diff) |
If stats file doesn't exist lfs_emubd_create will fail.
This will create default stats file if it doesn't exist.
Diffstat (limited to 'emubd')
-rw-r--r-- | emubd/lfs_emubd.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/emubd/lfs_emubd.c b/emubd/lfs_emubd.c index 682ad92..e44602c 100644 --- a/emubd/lfs_emubd.c +++ b/emubd/lfs_emubd.c @@ -47,19 +47,24 @@ int lfs_emubd_create(const struct lfs_config *cfg, const char *path) { // Load stats to continue incrementing snprintf(emu->child, LFS_NAME_MAX, "stats"); + FILE *f = fopen(emu->path, "r"); - if (!f) { + if (!f && errno != ENOENT) { return -errno; } - size_t res = fread(&emu->stats, sizeof(emu->stats), 1, f); - if (res < 1) { - return -errno; - } + if (errno == ENOENT) { + memset(&emu->stats, 0x0, sizeof(emu->stats)); + } else { + size_t res = fread(&emu->stats, sizeof(emu->stats), 1, f); + if (res < 1) { + return -errno; + } - err = fclose(f); - if (err) { - return -errno; + err = fclose(f); + if (err) { + return -errno; + } } return 0; |