From 4ecf5062e3b4f6b9604e83090d4e27306ee381fc Mon Sep 17 00:00:00 2001 From: Jozef Kralik Date: Fri, 1 Sep 2023 08:35:13 +0000 Subject: [PATCH] linux/storage: Add debug log for fopen failure on non-existent files --- port/linux/storage.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/port/linux/storage.c b/port/linux/storage.c index bf8ca27cc7..6620120ad3 100644 --- a/port/linux/storage.c +++ b/port/linux/storage.c @@ -33,6 +33,8 @@ #include #include #include +#include +#include static char g_store_path[OC_STORE_PATH_SIZE] = { 0 }; static uint8_t g_store_path_len = 0; @@ -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) {