annotate tests/test-linkat.c @ 40057:b06060465f09

maint: Run 'make update-copyright'
author Paul Eggert <eggert@cs.ucla.edu>
date Tue, 01 Jan 2019 00:25:11 +0100
parents 10eb9086bea0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12068
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
1 /* Tests of linkat.
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 19484
diff changeset
2 Copyright (C) 2009-2019 Free Software Foundation, Inc.
12068
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
3
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
7 (at your option) any later version.
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
8
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
12 GNU General Public License for more details.
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
13
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
19190
9759915b2aca all: prefer https: URLs
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
12068
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
16
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
17 /* Written by Eric Blake <ebb9@byu.net>, 2009. */
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
18
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
19 #include <config.h>
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
20
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
21 #include <unistd.h>
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
22
12489
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12263
diff changeset
23 #include "signature.h"
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12263
diff changeset
24 SIGNATURE_CHECK (linkat, int, (int, char const *, int, char const *, int));
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12263
diff changeset
25
12068
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
26 #include <fcntl.h>
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
27 #include <errno.h>
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
28 #include <stdbool.h>
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
29 #include <stdio.h>
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
30 #include <stdlib.h>
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
31 #include <string.h>
13405
e7645f87b96f test-linkat: avoid failed assertion on "other" architectures
Jim Meyering <meyering@redhat.com>
parents: 12842
diff changeset
32 #include <sys/stat.h>
12068
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
33
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
34 #include "areadlink.h"
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
35 #include "filenamecat.h"
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
36 #include "same-inode.h"
12842
b2bf8684a2db tests: silence warning about system return
Eric Blake <ebb9@byu.net>
parents: 12559
diff changeset
37 #include "ignore-value.h"
12496
a48d3d749ca5 Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents: 12489
diff changeset
38 #include "macros.h"
12068
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
39
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
40 #define BASE "test-linkat.t"
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
41
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
42 #include "test-link.h"
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
43
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
44 static int dfd1 = AT_FDCWD;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
45 static int dfd2 = AT_FDCWD;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
46 static int flag = AT_SYMLINK_FOLLOW;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
47
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
48 /* Wrapper to test linkat like link. */
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
49 static int
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
50 do_link (char const *name1, char const *name2)
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
51 {
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
52 return linkat (dfd1, name1, dfd2, name2, flag);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
53 }
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
54
14050
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 14048
diff changeset
55 /* Can we expect that link() and linkat(), when called on a symlink,
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 14048
diff changeset
56 increment the link count of that symlink? */
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 14048
diff changeset
57 #if LINK_FOLLOWS_SYMLINKS == 0
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 14048
diff changeset
58 # define EXPECT_LINK_HARDLINKS_SYMLINKS 1
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 14048
diff changeset
59 #elif LINK_FOLLOWS_SYMLINKS == -1
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 14048
diff changeset
60 extern int __xpg4;
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 14048
diff changeset
61 # define EXPECT_LINK_HARDLINKS_SYMLINKS (__xpg4 == 0)
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 14048
diff changeset
62 #else
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 14048
diff changeset
63 # define EXPECT_LINK_HARDLINKS_SYMLINKS 0
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 14048
diff changeset
64 #endif
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 14048
diff changeset
65
12068
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
66 /* Wrapper to see if two symlinks act the same. */
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
67 static void
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
68 check_same_link (char const *name1, char const *name2)
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
69 {
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
70 struct stat st1;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
71 struct stat st2;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
72 char *contents1;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
73 char *contents2;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
74 ASSERT (lstat (name1, &st1) == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
75 ASSERT (lstat (name2, &st2) == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
76 contents1 = areadlink_with_size (name1, st1.st_size);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
77 contents2 = areadlink_with_size (name2, st2.st_size);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
78 ASSERT (contents1);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
79 ASSERT (contents2);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
80 ASSERT (strcmp (contents1, contents2) == 0);
14050
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 14048
diff changeset
81 if (EXPECT_LINK_HARDLINKS_SYMLINKS)
12068
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
82 ASSERT (SAME_INODE (st1, st2));
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
83 free (contents1);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
84 free (contents2);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
85 }
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
86
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
87 int
12197
e45d9bb2233e tests: avoid several compiler warnings
Eric Blake <ebb9@byu.net>
parents: 12146
diff changeset
88 main (void)
12068
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
89 {
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
90 int i;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
91 int dfd;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
92 char *cwd;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
93 int result;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
94
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
95 /* Clean up any trash from prior testsuite runs. */
12842
b2bf8684a2db tests: silence warning about system return
Eric Blake <ebb9@byu.net>
parents: 12559
diff changeset
96 ignore_value (system ("rm -rf " BASE "*"));
12068
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
97
15703
97b70675b25e linkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 15298
diff changeset
98 /* Test behaviour for invalid file descriptors. */
97b70675b25e linkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 15298
diff changeset
99 {
97b70675b25e linkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 15298
diff changeset
100 errno = 0;
97b70675b25e linkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 15298
diff changeset
101 ASSERT (linkat (-1, "foo", AT_FDCWD, "bar", 0) == -1);
97b70675b25e linkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 15298
diff changeset
102 ASSERT (errno == EBADF);
97b70675b25e linkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 15298
diff changeset
103 }
97b70675b25e linkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 15298
diff changeset
104 {
17292
3a09cc104f4c tests: don't assume fd 99 is closed
Paul Eggert <eggert@cs.ucla.edu>
parents: 17249
diff changeset
105 close (99);
15703
97b70675b25e linkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 15298
diff changeset
106 errno = 0;
97b70675b25e linkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 15298
diff changeset
107 ASSERT (linkat (99, "foo", AT_FDCWD, "bar", 0) == -1);
97b70675b25e linkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 15298
diff changeset
108 ASSERT (errno == EBADF);
97b70675b25e linkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 15298
diff changeset
109 }
97b70675b25e linkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 15298
diff changeset
110 ASSERT (close (creat (BASE "oo", 0600)) == 0);
97b70675b25e linkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 15298
diff changeset
111 {
97b70675b25e linkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 15298
diff changeset
112 errno = 0;
97b70675b25e linkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 15298
diff changeset
113 ASSERT (linkat (AT_FDCWD, BASE "oo", -1, "bar", 0) == -1);
97b70675b25e linkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 15298
diff changeset
114 ASSERT (errno == EBADF);
97b70675b25e linkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 15298
diff changeset
115 }
97b70675b25e linkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 15298
diff changeset
116 {
97b70675b25e linkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 15298
diff changeset
117 errno = 0;
97b70675b25e linkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 15298
diff changeset
118 ASSERT (linkat (AT_FDCWD, BASE "oo", 99, "bar", 0) == -1);
97b70675b25e linkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 15298
diff changeset
119 ASSERT (errno == EBADF);
97b70675b25e linkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 15298
diff changeset
120 }
15810
bf1b12f633c4 test-linkat: don't leave behind a temporary file
Jim Meyering <meyering@redhat.com>
parents: 15703
diff changeset
121 ASSERT (unlink (BASE "oo") == 0);
15703
97b70675b25e linkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 15298
diff changeset
122
12068
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
123 /* Test basic link functionality, without mentioning symlinks. */
12263
c689d1419da9 link: detect FreeBSD bug
Eric Blake <ebb9@byu.net>
parents: 12197
diff changeset
124 result = test_link (do_link, true);
12084
34277de50e87 tests: tighten link, rmdir, and remove tests
Eric Blake <ebb9@byu.net>
parents: 12071
diff changeset
125 dfd1 = open (".", O_RDONLY);
34277de50e87 tests: tighten link, rmdir, and remove tests
Eric Blake <ebb9@byu.net>
parents: 12071
diff changeset
126 ASSERT (0 <= dfd1);
34277de50e87 tests: tighten link, rmdir, and remove tests
Eric Blake <ebb9@byu.net>
parents: 12071
diff changeset
127 ASSERT (test_link (do_link, false) == result);
34277de50e87 tests: tighten link, rmdir, and remove tests
Eric Blake <ebb9@byu.net>
parents: 12071
diff changeset
128 dfd2 = dfd1;
34277de50e87 tests: tighten link, rmdir, and remove tests
Eric Blake <ebb9@byu.net>
parents: 12071
diff changeset
129 ASSERT (test_link (do_link, false) == result);
34277de50e87 tests: tighten link, rmdir, and remove tests
Eric Blake <ebb9@byu.net>
parents: 12071
diff changeset
130 dfd1 = AT_FDCWD;
34277de50e87 tests: tighten link, rmdir, and remove tests
Eric Blake <ebb9@byu.net>
parents: 12071
diff changeset
131 ASSERT (test_link (do_link, false) == result);
34277de50e87 tests: tighten link, rmdir, and remove tests
Eric Blake <ebb9@byu.net>
parents: 12071
diff changeset
132 flag = 0;
34277de50e87 tests: tighten link, rmdir, and remove tests
Eric Blake <ebb9@byu.net>
parents: 12071
diff changeset
133 ASSERT (test_link (do_link, false) == result);
34277de50e87 tests: tighten link, rmdir, and remove tests
Eric Blake <ebb9@byu.net>
parents: 12071
diff changeset
134 dfd1 = dfd2;
34277de50e87 tests: tighten link, rmdir, and remove tests
Eric Blake <ebb9@byu.net>
parents: 12071
diff changeset
135 ASSERT (test_link (do_link, false) == result);
34277de50e87 tests: tighten link, rmdir, and remove tests
Eric Blake <ebb9@byu.net>
parents: 12071
diff changeset
136 dfd2 = AT_FDCWD;
34277de50e87 tests: tighten link, rmdir, and remove tests
Eric Blake <ebb9@byu.net>
parents: 12071
diff changeset
137 ASSERT (test_link (do_link, false) == result);
34277de50e87 tests: tighten link, rmdir, and remove tests
Eric Blake <ebb9@byu.net>
parents: 12071
diff changeset
138 ASSERT (close (dfd1) == 0);
34277de50e87 tests: tighten link, rmdir, and remove tests
Eric Blake <ebb9@byu.net>
parents: 12071
diff changeset
139 dfd1 = AT_FDCWD;
34277de50e87 tests: tighten link, rmdir, and remove tests
Eric Blake <ebb9@byu.net>
parents: 12071
diff changeset
140 ASSERT (test_link (do_link, false) == result);
12068
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
141
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
142 /* Create locations to manipulate. */
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
143 ASSERT (mkdir (BASE "sub1", 0700) == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
144 ASSERT (mkdir (BASE "sub2", 0700) == 0);
12084
34277de50e87 tests: tighten link, rmdir, and remove tests
Eric Blake <ebb9@byu.net>
parents: 12071
diff changeset
145 ASSERT (close (creat (BASE "00", 0600)) == 0);
14632
4843b6870f07 tests: reduce dependencies
Eric Blake <eblake@redhat.com>
parents: 14079
diff changeset
146 cwd = getcwd (NULL, 0);
4843b6870f07 tests: reduce dependencies
Eric Blake <eblake@redhat.com>
parents: 14079
diff changeset
147 ASSERT (cwd);
12068
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
148
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
149 dfd = open (BASE "sub1", O_RDONLY);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
150 ASSERT (0 <= dfd);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
151 ASSERT (chdir (BASE "sub2") == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
152
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
153 /* There are 16 possible scenarios, based on whether an fd is
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
154 AT_FDCWD or real, whether a file is absolute or relative, coupled
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
155 with whether flag is set for 32 iterations.
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
156
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
157 To ensure that we test all of the code paths (rather than
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
158 triggering early normalization optimizations), we use a loop to
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
159 repeatedly rename a file in the parent directory, use an fd open
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
160 on subdirectory 1, all while executing in subdirectory 2; all
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
161 relative names are thus given with a leading "../". Finally, the
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
162 last scenario (two relative paths given, neither one AT_FDCWD)
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
163 has two paths, based on whether the two fds are equivalent, so we
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
164 do the other variant after the loop. */
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
165 for (i = 0; i < 32; i++)
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
166 {
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
167 int fd1 = (i & 8) ? dfd : AT_FDCWD;
14645
5c448b1cba39 tests: drop unused link dependency
Eric Blake <eblake@redhat.com>
parents: 14632
diff changeset
168 char *file1 = mfile_name_concat ((i & 4) ? ".." : cwd, BASE "xx", NULL);
12068
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
169 int fd2 = (i & 2) ? dfd : AT_FDCWD;
14645
5c448b1cba39 tests: drop unused link dependency
Eric Blake <eblake@redhat.com>
parents: 14632
diff changeset
170 char *file2 = mfile_name_concat ((i & 1) ? ".." : cwd, BASE "xx", NULL);
5c448b1cba39 tests: drop unused link dependency
Eric Blake <eblake@redhat.com>
parents: 14632
diff changeset
171 ASSERT (file1);
5c448b1cba39 tests: drop unused link dependency
Eric Blake <eblake@redhat.com>
parents: 14632
diff changeset
172 ASSERT (file2);
12197
e45d9bb2233e tests: avoid several compiler warnings
Eric Blake <ebb9@byu.net>
parents: 12146
diff changeset
173 flag = (i & 0x10 ? AT_SYMLINK_FOLLOW : 0);
12068
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
174
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
175 ASSERT (sprintf (strchr (file1, '\0') - 2, "%02d", i) == 2);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
176 ASSERT (sprintf (strchr (file2, '\0') - 2, "%02d", i + 1) == 2);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
177 ASSERT (linkat (fd1, file1, fd2, file2, flag) == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
178 ASSERT (unlinkat (fd1, file1, 0) == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
179 free (file1);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
180 free (file2);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
181 }
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
182 dfd2 = open ("..", O_RDONLY);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
183 ASSERT (0 <= dfd2);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
184 ASSERT (linkat (dfd, "../" BASE "32", dfd2, BASE "33", 0) == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
185 ASSERT (linkat (dfd, "../" BASE "33", dfd2, BASE "34",
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
186 AT_SYMLINK_FOLLOW) == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
187 ASSERT (close (dfd2) == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
188
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
189 /* Now we change back to the parent directory, and set dfd to ".",
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
190 in order to test behavior on symlinks. */
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
191 ASSERT (chdir ("..") == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
192 ASSERT (close (dfd) == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
193 if (symlink (BASE "sub1", BASE "link1"))
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
194 {
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
195 ASSERT (unlink (BASE "32") == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
196 ASSERT (unlink (BASE "33") == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
197 ASSERT (unlink (BASE "34") == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
198 ASSERT (rmdir (BASE "sub1") == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
199 ASSERT (rmdir (BASE "sub2") == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
200 free (cwd);
12263
c689d1419da9 link: detect FreeBSD bug
Eric Blake <ebb9@byu.net>
parents: 12197
diff changeset
201 if (!result)
c689d1419da9 link: detect FreeBSD bug
Eric Blake <ebb9@byu.net>
parents: 12197
diff changeset
202 fputs ("skipping test: symlinks not supported on this file system\n",
c689d1419da9 link: detect FreeBSD bug
Eric Blake <ebb9@byu.net>
parents: 12197
diff changeset
203 stderr);
12068
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
204 return result;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
205 }
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
206 dfd = open (".", O_RDONLY);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
207 ASSERT (0 <= dfd);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
208 ASSERT (symlink (BASE "34", BASE "link2") == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
209 ASSERT (symlink (BASE "link3", BASE "link3") == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
210 ASSERT (symlink (BASE "nowhere", BASE "link4") == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
211
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
212 /* Link cannot overwrite existing files. */
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
213 errno = 0;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
214 ASSERT (linkat (dfd, BASE "link1", dfd, BASE "sub1", 0) == -1);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
215 ASSERT (errno == EEXIST);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
216 errno = 0;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
217 ASSERT (linkat (dfd, BASE "link1/", dfd, BASE "sub1", 0) == -1);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
218 ASSERT (errno == EEXIST || errno == EPERM || errno == EACCES);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
219 errno = 0;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
220 ASSERT (linkat (dfd, BASE "link1", dfd, BASE "sub1/", 0) == -1);
14048
2defc00f2b21 linkat test: Avoid failure on Solaris 11 2010-11.
Bruno Haible <bruno@clisp.org>
parents: 13405
diff changeset
221 ASSERT (errno == EEXIST || errno == ENOTDIR);
12068
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
222 errno = 0;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
223 ASSERT (linkat (dfd, BASE "link1", dfd, BASE "sub1",
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
224 AT_SYMLINK_FOLLOW) == -1);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
225 ASSERT (errno == EEXIST || errno == EPERM || errno == EACCES);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
226 errno = 0;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
227 ASSERT (linkat (dfd, BASE "link1/", dfd, BASE "sub1",
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
228 AT_SYMLINK_FOLLOW) == -1);
15298
9f6aa6c9dd0e linkat test: Avoid test failure on AIX 7.1.
Bruno Haible <bruno@clisp.org>
parents: 14645
diff changeset
229 ASSERT (errno == EEXIST || errno == EPERM || errno == EACCES
9f6aa6c9dd0e linkat test: Avoid test failure on AIX 7.1.
Bruno Haible <bruno@clisp.org>
parents: 14645
diff changeset
230 || errno == EINVAL);
12068
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
231 errno = 0;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
232 ASSERT (linkat (dfd, BASE "link1", dfd, BASE "sub1/",
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
233 AT_SYMLINK_FOLLOW) == -1);
15298
9f6aa6c9dd0e linkat test: Avoid test failure on AIX 7.1.
Bruno Haible <bruno@clisp.org>
parents: 14645
diff changeset
234 ASSERT (errno == EEXIST || errno == EPERM || errno == EACCES
9f6aa6c9dd0e linkat test: Avoid test failure on AIX 7.1.
Bruno Haible <bruno@clisp.org>
parents: 14645
diff changeset
235 || errno == EINVAL);
12068
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
236 errno = 0;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
237 ASSERT (linkat (dfd, BASE "link1", dfd, BASE "link2", 0) == -1);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
238 ASSERT (errno == EEXIST);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
239 errno = 0;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
240 ASSERT (linkat (dfd, BASE "link1", dfd, BASE "link2",
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
241 AT_SYMLINK_FOLLOW) == -1);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
242 ASSERT (errno == EEXIST || errno == EPERM || errno == EACCES);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
243 errno = 0;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
244 ASSERT (linkat (dfd, BASE "link1", dfd, BASE "link3", 0) == -1);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
245 ASSERT (errno == EEXIST || errno == ELOOP);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
246 errno = 0;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
247 ASSERT (linkat (dfd, BASE "link1", dfd, BASE "link3",
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
248 AT_SYMLINK_FOLLOW) == -1);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
249 ASSERT (errno == EEXIST || errno == EPERM || errno == EACCES
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
250 || errno == ELOOP);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
251 errno = 0;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
252 ASSERT (linkat (dfd, BASE "link2", dfd, BASE "link3", 0) == -1);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
253 ASSERT (errno == EEXIST || errno == ELOOP);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
254 errno = 0;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
255 ASSERT (linkat (dfd, BASE "link2", dfd, BASE "link3",
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
256 AT_SYMLINK_FOLLOW) == -1);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
257 ASSERT (errno == EEXIST || errno == ELOOP);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
258
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
259 /* AT_SYMLINK_FOLLOW only follows first argument, not second. */
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
260 errno = 0;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
261 ASSERT (linkat (dfd, BASE "link1", dfd, BASE "link4", 0) == -1);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
262 ASSERT (errno == EEXIST);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
263 ASSERT (linkat (dfd, BASE "link1", dfd, BASE "link4",
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
264 AT_SYMLINK_FOLLOW) == -1);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
265 ASSERT (errno == EEXIST || errno == EPERM || errno == EACCES);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
266 errno = 0;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
267 ASSERT (linkat (dfd, BASE "34", dfd, BASE "link4", 0) == -1);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
268 ASSERT (errno == EEXIST);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
269 errno = 0;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
270 ASSERT (linkat (dfd, BASE "34", dfd, BASE "link4", AT_SYMLINK_FOLLOW) == -1);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
271 ASSERT (errno == EEXIST);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
272
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
273 /* Trailing slash handling. */
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
274 errno = 0;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
275 ASSERT (linkat (dfd, BASE "link2/", dfd, BASE "link5", 0) == -1);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
276 ASSERT (errno == ENOTDIR);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
277 errno = 0;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
278 ASSERT (linkat (dfd, BASE "link2/", dfd, BASE "link5",
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
279 AT_SYMLINK_FOLLOW) == -1);
15298
9f6aa6c9dd0e linkat test: Avoid test failure on AIX 7.1.
Bruno Haible <bruno@clisp.org>
parents: 14645
diff changeset
280 ASSERT (errno == ENOTDIR || errno == EINVAL);
12068
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
281 errno = 0;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
282 ASSERT (linkat (dfd, BASE "link3/", dfd, BASE "link5", 0) == -1);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
283 ASSERT (errno == ELOOP);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
284 errno = 0;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
285 ASSERT (linkat (dfd, BASE "link3/", dfd, BASE "link5",
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
286 AT_SYMLINK_FOLLOW) == -1);
15298
9f6aa6c9dd0e linkat test: Avoid test failure on AIX 7.1.
Bruno Haible <bruno@clisp.org>
parents: 14645
diff changeset
287 ASSERT (errno == ELOOP || errno == EINVAL);
12068
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
288 errno = 0;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
289 ASSERT (linkat (dfd, BASE "link4/", dfd, BASE "link5", 0) == -1);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
290 ASSERT (errno == ENOENT);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
291 errno = 0;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
292 ASSERT (linkat (dfd, BASE "link4/", dfd, BASE "link5",
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
293 AT_SYMLINK_FOLLOW) == -1);
15298
9f6aa6c9dd0e linkat test: Avoid test failure on AIX 7.1.
Bruno Haible <bruno@clisp.org>
parents: 14645
diff changeset
294 ASSERT (errno == ENOENT || errno == EINVAL);
12068
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
295
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
296 /* Check for hard links to symlinks. */
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
297 ASSERT (linkat (dfd, BASE "link1", dfd, BASE "link5", 0) == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
298 check_same_link (BASE "link1", BASE "link5");
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
299 ASSERT (unlink (BASE "link5") == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
300 errno = 0;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
301 ASSERT (linkat (dfd, BASE "link1", dfd, BASE "link5",
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
302 AT_SYMLINK_FOLLOW) == -1);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
303 ASSERT (errno == EPERM || errno == EACCES);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
304 ASSERT (linkat (dfd, BASE "link2", dfd, BASE "link5", 0) == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
305 check_same_link (BASE "link2", BASE "link5");
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
306 ASSERT (unlink (BASE "link5") == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
307 ASSERT (linkat (dfd, BASE "link2", dfd, BASE "file", AT_SYMLINK_FOLLOW) == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
308 errno = 0;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
309 ASSERT (areadlink (BASE "file") == NULL);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
310 ASSERT (errno == EINVAL);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
311 ASSERT (unlink (BASE "file") == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
312 ASSERT (linkat (dfd, BASE "link3", dfd, BASE "link5", 0) == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
313 check_same_link (BASE "link3", BASE "link5");
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
314 ASSERT (unlink (BASE "link5") == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
315 errno = 0;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
316 ASSERT (linkat (dfd, BASE "link3", dfd, BASE "link5",
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
317 AT_SYMLINK_FOLLOW) == -1);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
318 ASSERT (errno == ELOOP);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
319 ASSERT (linkat (dfd, BASE "link4", dfd, BASE "link5", 0) == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
320 check_same_link (BASE "link4", BASE "link5");
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
321 ASSERT (unlink (BASE "link5") == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
322 errno = 0;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
323 ASSERT (linkat (dfd, BASE "link4", dfd, BASE "link5",
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
324 AT_SYMLINK_FOLLOW) == -1);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
325 ASSERT (errno == ENOENT);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
326
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
327 /* Check that symlink to symlink to file is followed all the way. */
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
328 ASSERT (symlink (BASE "link2", BASE "link5") == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
329 ASSERT (linkat (dfd, BASE "link5", dfd, BASE "link6", 0) == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
330 check_same_link (BASE "link5", BASE "link6");
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
331 ASSERT (unlink (BASE "link6") == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
332 ASSERT (linkat (dfd, BASE "link5", dfd, BASE "file", AT_SYMLINK_FOLLOW) == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
333 errno = 0;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
334 ASSERT (areadlink (BASE "file") == NULL);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
335 ASSERT (errno == EINVAL);
12071
8ae42b7a9fe9 test-linkat: make test more robust
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
336 ASSERT (unlink (BASE "file") == 0);
12068
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
337 ASSERT (unlink (BASE "link5") == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
338 ASSERT (symlink (BASE "link3", BASE "link5") == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
339 errno = 0;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
340 ASSERT (linkat (dfd, BASE "link5", dfd, BASE "file",
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
341 AT_SYMLINK_FOLLOW) == -1);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
342 ASSERT (errno == ELOOP);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
343 ASSERT (unlink (BASE "link5") == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
344 ASSERT (symlink (BASE "link4", BASE "link5") == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
345 errno = 0;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
346 ASSERT (linkat (dfd, BASE "link5", dfd, BASE "file",
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
347 AT_SYMLINK_FOLLOW) == -1);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
348 ASSERT (errno == ENOENT);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
349
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
350 /* Now for some real fun with directory crossing. */
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
351 ASSERT (symlink (cwd, BASE "sub1/link") == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
352 ASSERT (symlink (".././/" BASE "sub1/link/" BASE "link2",
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
353 BASE "sub2/link") == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
354 ASSERT (close (dfd) == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
355 dfd = open (BASE "sub1", O_RDONLY);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
356 ASSERT (0 <= dfd);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
357 dfd2 = open (BASE "sub2", O_RDONLY);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
358 ASSERT (0 < dfd2);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
359 ASSERT (linkat (dfd, "../" BASE "sub2/link", dfd2, "./..//" BASE "sub1/file",
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
360 AT_SYMLINK_FOLLOW) == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
361 errno = 0;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
362 ASSERT (areadlink (BASE "sub1/file") == NULL);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
363 ASSERT (errno == EINVAL);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
364
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
365 /* Cleanup. */
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
366 ASSERT (close (dfd) == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
367 ASSERT (close (dfd2) == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
368 ASSERT (unlink (BASE "sub1/file") == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
369 ASSERT (unlink (BASE "sub1/link") == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
370 ASSERT (unlink (BASE "sub2/link") == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
371 ASSERT (unlink (BASE "32") == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
372 ASSERT (unlink (BASE "33") == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
373 ASSERT (unlink (BASE "34") == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
374 ASSERT (rmdir (BASE "sub1") == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
375 ASSERT (rmdir (BASE "sub2") == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
376 ASSERT (unlink (BASE "link1") == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
377 ASSERT (unlink (BASE "link2") == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
378 ASSERT (unlink (BASE "link3") == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
379 ASSERT (unlink (BASE "link4") == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
380 ASSERT (unlink (BASE "link5") == 0);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
381 free (cwd);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
382 return result;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
383 }