]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-device: introduce devname_from_stat_rdev()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 2 Sep 2022 15:35:34 +0000 (00:35 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 2 Sep 2022 15:42:31 +0000 (00:42 +0900)
src/libsystemd/sd-device/device-util.h
src/libsystemd/sd-device/test-sd-device.c

index b9a29f692484cf480e9d27e539cf3e9830241222..0561a172ae42c7b64166cc100a03a2708dfcc511 100644 (file)
@@ -2,6 +2,7 @@
 #pragma once
 
 #include <stdbool.h>
+#include <sys/stat.h>
 #include <sys/types.h>
 
 #include "sd-device.h"
@@ -82,4 +83,8 @@
 #define log_device_error_errno(device, error, ...)   log_device_full_errno(device, LOG_ERR, error, __VA_ARGS__)
 
 int devname_from_devnum(mode_t mode, dev_t devnum, char **ret);
+static inline int devname_from_stat_rdev(const struct stat *st, char **ret) {
+        assert(st);
+        return devname_from_devnum(st->st_mode, st->st_rdev, ret);
+}
 int device_open_from_devnum(mode_t mode, dev_t devnum, int flags, char **ret);
index 758a2a380d2e6614324870a316865293da8dea06..0016aa08e74238422ccacea92b96a195d4ce473d 100644 (file)
@@ -514,6 +514,9 @@ static void test_devname_from_devnum_one(const char *path) {
 
         assert_se(devname_from_devnum(st.st_mode, st.st_rdev, &resolved) >= 0);
         assert_se(path_equal(path, resolved));
+        resolved = mfree(resolved);
+        assert_se(devname_from_stat_rdev(&st, &resolved) >= 0);
+        assert_se(path_equal(path, resolved));
 }
 
 TEST(devname_from_devnum) {