summaryrefslogtreecommitdiff
path: root/lib/sysfs_utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sysfs_utils.c')
-rw-r--r--lib/sysfs_utils.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/sysfs_utils.c b/lib/sysfs_utils.c
index 7b71639..dd424f1 100644
--- a/lib/sysfs_utils.c
+++ b/lib/sysfs_utils.c
@@ -377,3 +377,26 @@ int sysfs_path_is_link(const unsigned char *path)
return 1;
}
+
+/**
+ * sysfs_path_is_file: Check if the path supplied points to a file
+ * @path: path to validate
+ * Returns 0 if path points to file, 1 otherwise
+ */
+int sysfs_path_is_file(const unsigned char *path)
+{
+ struct stat astats;
+
+ if (path == NULL) {
+ errno = EINVAL;
+ return 1;
+ }
+ if ((lstat(path, &astats)) != 0) {
+ dprintf("stat() failed\n");
+ return 1;
+ }
+ if (S_ISREG(astats.st_mode))
+ return 0;
+
+ return 1;
+}