Skip to content

Commit

Permalink
If stats file doesn't exist lfs_emubd_create will fail.
Browse files Browse the repository at this point in the history
This will create default stats file if it doesn't exist.
  • Loading branch information
Chris authored and geky committed Sep 26, 2018
1 parent 3419284 commit 6ad544f
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions emubd/lfs_emubd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6ad544f

Please sign in to comment.