1 /* SPDX-License-Identifier: LGPL-2.1+ */
4 #include <linux/magic.h>
7 #include "alloc-util.h"
12 #include "mount-util.h"
13 #include "stat-util.h"
15 static void test_files_same(void) {
16 _cleanup_close_ int fd = -1;
17 char name[] = "/tmp/test-files_same.XXXXXX";
18 char name_alias[] = "/tmp/test-files_same.alias";
20 fd = mkostemp_safe(name);
22 assert_se(symlink(name, name_alias) >= 0);
24 assert_se(files_same(name, name, 0));
25 assert_se(files_same(name, name, AT_SYMLINK_NOFOLLOW));
26 assert_se(files_same(name, name_alias, 0));
27 assert_se(!files_same(name, name_alias, AT_SYMLINK_NOFOLLOW));
33 #if 0 /// UNNEEDED by elogind
34 static void test_is_symlink(void) {
35 char name[] = "/tmp/test-is_symlink.XXXXXX";
36 char name_link[] = "/tmp/test-is_symlink.link";
37 _cleanup_close_ int fd = -1;
39 fd = mkostemp_safe(name);
41 assert_se(symlink(name, name_link) >= 0);
43 assert_se(is_symlink(name) == 0);
44 assert_se(is_symlink(name_link) == 1);
45 assert_se(is_symlink("/a/file/which/does/not/exist/i/guess") < 0);
51 static void test_path_is_fs_type(void) {
52 /* run might not be a mount point in build chroots */
53 if (path_is_mount_point("/run", NULL, AT_SYMLINK_FOLLOW) > 0) {
54 assert_se(path_is_fs_type("/run", TMPFS_MAGIC) > 0);
55 assert_se(path_is_fs_type("/run", BTRFS_SUPER_MAGIC) == 0);
57 assert_se(path_is_fs_type("/proc", PROC_SUPER_MAGIC) > 0);
58 assert_se(path_is_fs_type("/proc", BTRFS_SUPER_MAGIC) == 0);
59 assert_se(path_is_fs_type("/proc", BTRFS_SUPER_MAGIC) == 0);
60 assert_se(path_is_fs_type("/i-dont-exist", BTRFS_SUPER_MAGIC) == -ENOENT);
63 static void test_path_is_temporary_fs(void) {
64 /* run might not be a mount point in build chroots */
65 if (path_is_mount_point("/run", NULL, AT_SYMLINK_FOLLOW) > 0)
66 assert_se(path_is_temporary_fs("/run") > 0);
67 assert_se(path_is_temporary_fs("/proc") == 0);
68 assert_se(path_is_temporary_fs("/i-dont-exist") == -ENOENT);
72 int main(int argc, char *argv[]) {
74 #if 0 /// UNNEEDED by elogind
76 test_path_is_fs_type();
77 test_path_is_temporary_fs();