]>
Commit | Line | Data |
---|---|---|
f4c13ad7 RC |
1 | /*** |
2 | This file is part of systemd. | |
3 | ||
4 | Copyright 2010 Lennart Poettering | |
5 | ||
6 | systemd is free software; you can redistribute it and/or modify it | |
7 | under the terms of the GNU Lesser General Public License as published by | |
8 | the Free Software Foundation; either version 2.1 of the License, or | |
9 | (at your option) any later version. | |
10 | ||
11 | systemd is distributed in the hope that it will be useful, but | |
12 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | Lesser General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU Lesser General Public License | |
17 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
18 | ***/ | |
19 | ||
20 | #include <fcntl.h> | |
21 | #include <unistd.h> | |
22 | ||
23 | #include "alloc-util.h" | |
24 | #include "fd-util.h" | |
25 | #include "fileio.h" | |
26 | #include "macro.h" | |
27 | #include "stat-util.h" | |
28 | ||
29 | static void test_files_same(void) { | |
30 | _cleanup_close_ int fd = -1; | |
31 | char name[] = "/tmp/test-files_same.XXXXXX"; | |
32 | char name_alias[] = "/tmp/test-files_same.alias"; | |
33 | ||
646853bd | 34 | fd = mkostemp_safe(name); |
f4c13ad7 RC |
35 | assert_se(fd >= 0); |
36 | assert_se(symlink(name, name_alias) >= 0); | |
37 | ||
38 | assert_se(files_same(name, name)); | |
39 | assert_se(files_same(name, name_alias)); | |
40 | ||
41 | unlink(name); | |
42 | unlink(name_alias); | |
43 | } | |
44 | ||
45 | static void test_is_symlink(void) { | |
46 | char name[] = "/tmp/test-is_symlink.XXXXXX"; | |
47 | char name_link[] = "/tmp/test-is_symlink.link"; | |
48 | _cleanup_close_ int fd = -1; | |
49 | ||
646853bd | 50 | fd = mkostemp_safe(name); |
f4c13ad7 RC |
51 | assert_se(fd >= 0); |
52 | assert_se(symlink(name, name_link) >= 0); | |
53 | ||
54 | assert_se(is_symlink(name) == 0); | |
55 | assert_se(is_symlink(name_link) == 1); | |
56 | assert_se(is_symlink("/a/file/which/does/not/exist/i/guess") < 0); | |
57 | ||
58 | ||
59 | unlink(name); | |
60 | unlink(name_link); | |
61 | } | |
62 | ||
63 | int main(int argc, char *argv[]) { | |
64 | test_files_same(); | |
65 | test_is_symlink(); | |
66 | ||
67 | return 0; | |
68 | } |