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 committed Sep 1, 2023
1 parent a8817c1 commit 4ecf506
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions port/linux/storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>

static char g_store_path[OC_STORE_PATH_SIZE] = { 0 };
static uint8_t g_store_path_len = 0;
Expand Down Expand Up @@ -123,8 +125,16 @@ 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
struct stat st;
int fopen_errno = errno;
if (stat(g_store_path, &st) == 0) {
OC_ERR("failed to open %s for read: %d", g_store_path, fopen_errno);
return -errno;
}
#endif /* OC_ERR_IS_ENABLED */
OC_DBG("failed to open %s for read: %d", g_store_path, fopen_errno);
return -errno;
}

if (fseek(fp, 0, SEEK_END) != 0) {
Expand Down

0 comments on commit 4ecf506

Please sign in to comment.