1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2010 Lennart Poettering
9 #include <linux/magic.h>
12 #include "alloc-util.h"
17 #include "mount-util.h"
18 #include "stat-util.h"
20 static void test_files_same(void) {
21 _cleanup_close_ int fd = -1;
22 char name[] = "/tmp/test-files_same.XXXXXX";
23 char name_alias[] = "/tmp/test-files_same.alias";
25 fd = mkostemp_safe(name);
27 assert_se(symlink(name, name_alias) >= 0);
29 assert_se(files_same(name, name, 0));
30 assert_se(files_same(name, name, AT_SYMLINK_NOFOLLOW));
31 assert_se(files_same(name, name_alias, 0));
32 assert_se(!files_same(name, name_alias, AT_SYMLINK_NOFOLLOW));
38 #if 0 /// UNNEEDED by elogind
39 static void test_is_symlink(void) {
40 char name[] = "/tmp/test-is_symlink.XXXXXX";
41 char name_link[] = "/tmp/test-is_symlink.link";
42 _cleanup_close_ int fd = -1;
44 fd = mkostemp_safe(name);
46 assert_se(symlink(name, name_link) >= 0);
48 assert_se(is_symlink(name) == 0);
49 assert_se(is_symlink(name_link) == 1);
50 assert_se(is_symlink("/a/file/which/does/not/exist/i/guess") < 0);
56 static void test_path_is_fs_type(void) {
57 /* run might not be a mount point in build chroots */
58 if (path_is_mount_point("/run", NULL, AT_SYMLINK_FOLLOW) > 0) {
59 assert_se(path_is_fs_type("/run", TMPFS_MAGIC) > 0);
60 assert_se(path_is_fs_type("/run", BTRFS_SUPER_MAGIC) == 0);
62 assert_se(path_is_fs_type("/proc", PROC_SUPER_MAGIC) > 0);
63 assert_se(path_is_fs_type("/proc", BTRFS_SUPER_MAGIC) == 0);
64 assert_se(path_is_fs_type("/proc", BTRFS_SUPER_MAGIC) == 0);
65 assert_se(path_is_fs_type("/i-dont-exist", BTRFS_SUPER_MAGIC) == -ENOENT);
68 static void test_path_is_temporary_fs(void) {
69 /* run might not be a mount point in build chroots */
70 if (path_is_mount_point("/run", NULL, AT_SYMLINK_FOLLOW) > 0)
71 assert_se(path_is_temporary_fs("/run") > 0);
72 assert_se(path_is_temporary_fs("/proc") == 0);
73 assert_se(path_is_temporary_fs("/i-dont-exist") == -ENOENT);
77 int main(int argc, char *argv[]) {
79 #if 0 /// UNNEEDED by elogind
81 test_path_is_fs_type();
82 test_path_is_temporary_fs();