]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-stat-util.c
1697b2d777f99e57c4e5469a8649a7166261db6d
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 static void test_is_symlink(void) {
39 char name
[] = "/tmp/test-is_symlink.XXXXXX";
40 char name_link
[] = "/tmp/test-is_symlink.link";
41 _cleanup_close_
int fd
= -1;
43 fd
= mkostemp_safe(name
);
45 assert_se(symlink(name
, name_link
) >= 0);
47 assert_se(is_symlink(name
) == 0);
48 assert_se(is_symlink(name_link
) == 1);
49 assert_se(is_symlink("/a/file/which/does/not/exist/i/guess") < 0);
55 static void test_path_is_fs_type(void) {
56 /* run might not be a mount point in build chroots */
57 if (path_is_mount_point("/run", NULL
, AT_SYMLINK_FOLLOW
) > 0) {
58 assert_se(path_is_fs_type("/run", TMPFS_MAGIC
) > 0);
59 assert_se(path_is_fs_type("/run", BTRFS_SUPER_MAGIC
) == 0);
61 assert_se(path_is_fs_type("/proc", PROC_SUPER_MAGIC
) > 0);
62 assert_se(path_is_fs_type("/proc", BTRFS_SUPER_MAGIC
) == 0);
63 assert_se(path_is_fs_type("/proc", BTRFS_SUPER_MAGIC
) == 0);
64 assert_se(path_is_fs_type("/i-dont-exist", BTRFS_SUPER_MAGIC
) == -ENOENT
);
67 static void test_path_is_temporary_fs(void) {
68 /* run might not be a mount point in build chroots */
69 if (path_is_mount_point("/run", NULL
, AT_SYMLINK_FOLLOW
) > 0)
70 assert_se(path_is_temporary_fs("/run") > 0);
71 assert_se(path_is_temporary_fs("/proc") == 0);
72 assert_se(path_is_temporary_fs("/i-dont-exist") == -ENOENT
);
75 int main(int argc
, char *argv
[]) {
78 test_path_is_fs_type();
79 test_path_is_temporary_fs();