Skip to content

Commit 1b7a155

Browse files
authored
Merge pull request ARMmbed#106 from conkerkh/master
If stats file doesn't exist lfs_emubd_create will fail.
2 parents e5a6938 + 6ad544f commit 1b7a155

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

emubd/lfs_emubd.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,24 @@ int lfs_emubd_create(const struct lfs_config *cfg, const char *path) {
4747

4848
// Load stats to continue incrementing
4949
snprintf(emu->child, LFS_NAME_MAX, "stats");
50+
5051
FILE *f = fopen(emu->path, "r");
51-
if (!f) {
52+
if (!f && errno != ENOENT) {
5253
return -errno;
5354
}
5455

55-
size_t res = fread(&emu->stats, sizeof(emu->stats), 1, f);
56-
if (res < 1) {
57-
return -errno;
58-
}
56+
if (errno == ENOENT) {
57+
memset(&emu->stats, 0x0, sizeof(emu->stats));
58+
} else {
59+
size_t res = fread(&emu->stats, sizeof(emu->stats), 1, f);
60+
if (res < 1) {
61+
return -errno;
62+
}
5963

60-
err = fclose(f);
61-
if (err) {
62-
return -errno;
64+
err = fclose(f);
65+
if (err) {
66+
return -errno;
67+
}
6368
}
6469

6570
return 0;

0 commit comments

Comments
 (0)