Skip to content

Commit

Permalink
linux/storage: Add debug log for fopen failure on non-existent files
Browse files Browse the repository at this point in the history
  • Loading branch information
jkralik authored and Daniel Adam committed Sep 2, 2023
1 parent 5d17d88 commit 7427aad
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions port/linux/storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,14 @@ oc_storage_read(const char *store, uint8_t *buf, size_t size)

FILE *fp = fopen(g_store_path, "rb");
if (fp == NULL) {
OC_ERR("failed to open %s for read: %d", g_store_path, errno);
return -EINVAL;
#if OC_ERR_IS_ENABLED
if (errno != ENOENT) {
OC_ERR("failed to open %s for read: %d", g_store_path, errno);
return -errno;
}
#endif /* OC_ERR_IS_ENABLED */
OC_DBG("failed to open %s for read: %d", g_store_path, errno);
return -errno;
}

if (fseek(fp, 0, SEEK_END) != 0) {
Expand Down Expand Up @@ -208,7 +214,7 @@ oc_storage_write(const char *store, const uint8_t *buf, size_t size)
FILE *fp = fopen(g_store_path, "wb");
if (fp == NULL) {
OC_ERR("failed to open %s for write: %d", g_store_path, errno);
return -EINVAL;
return -errno;
}

long ret = write_and_flush(fp, g_store_path, buf, size);
Expand Down

0 comments on commit 7427aad

Please sign in to comment.