sys: filesystem isfile function
MODIFY
include/re_sys.h
include/re_sys.h
@@ -72,3 +72,4 @@ void rand_bytes(uint8_t *p, size_t size);
int fs_mkdir(const char *path, uint16_t mode);
int fs_gethome(char *path, size_t sz);
bool fs_isdir(const char *path);
+bool fs_isfile(const char *file);

MODIFY
src/sys/fs.c
src/sys/fs.c
@@ -131,3 +131,27 @@ bool fs_isdir(const char *path)
return true;
}
+
+
+/**
+ * Check if given file exists and is a regular file
+ *
+ * @param file Filepath
+ *
+ * @return True if exists and is regular file, False if not
+ */
+bool fs_isfile(const char *file)
+{
+ struct stat st;
+
+ if (!file)
+ return false;
+
+ if (stat(file, &st) < 0)
+ return false;
+
+ if ((st.st_mode & S_IFMT) != S_IFREG)
+ return false;
+
+ return true;
+}

sys: filesystem isfile function