010d58d76c3ac8ab8a6b24b559b79556934c0d19
1 /* Test of rename() function.
2 Copyright (C) 2009-2017 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 /* This file is designed to test both rename(a,b) and
18 renameat(AT_FDCWD,a,AT_FDCWD,b). FUNC is the function to test.
19 Assumes that BASE and ASSERT are already defined, and that
20 appropriate headers are already included. If PRINT, warn before
21 skipping symlink tests with status 77. */
23 /* Tests whether a file, given by a file name without slashes, exists in
24 the current directory, by scanning the directory entries. */
26 dentry_exists (const char *filename
)
29 DIR *dir
= opendir (".");
34 struct dirent
*d
= readdir (dir
);
37 if (strcmp (d
->d_name
, filename
) == 0)
43 ASSERT (closedir (dir
) == 0);
47 /* Asserts that a specific file, given by a file name without slashes, does
48 not exist in the current directory. */
50 assert_nonexistent (const char *filename
)
54 /* The usual way to test the presence of a file is via stat() or lstat(). */
56 if (stat (filename
, &st
) == -1)
57 ASSERT (errno
== ENOENT
);
60 /* But after renaming a directory over an empty directory on an NFS-
61 mounted file system, on Linux 2.6.18, for a period of 30 seconds the
62 old directory name is "present" according to stat() but "nonexistent"
63 according to dentry_exists(). */
64 ASSERT (!dentry_exists (filename
));
65 /* Remove the old directory name, so that subsequent mkdir calls
67 (void) rmdir (filename
);
72 test_rename (int (*func
) (char const *, char const *), bool print
)
76 int fd
= creat (BASE
"file", 0600);
78 ASSERT (write (fd
, "hi", 2) == 2);
79 ASSERT (close (fd
) == 0);
80 ASSERT (mkdir (BASE
"dir", 0700) == 0);
82 /* Files present here:
89 { /* Missing source. */
92 ASSERT (func (BASE
"missing", BASE
"missing") == -1);
93 ASSERT (errno
== ENOENT
);
97 ASSERT (func (BASE
"missing/", BASE
"missing") == -1);
98 ASSERT (errno
== ENOENT
);
102 ASSERT (func (BASE
"missing", BASE
"missing/") == -1);
103 ASSERT (errno
== ENOENT
);
106 { /* Empty operand. */
109 ASSERT (func ("", BASE
"missing") == -1);
110 ASSERT (errno
== ENOENT
);
114 ASSERT (func (BASE
"file", "") == -1);
115 ASSERT (errno
== ENOENT
);
119 ASSERT (func (BASE
"", "") == -1);
120 ASSERT (errno
== ENOENT
);
126 { /* Trailing slash. */
129 ASSERT (func (BASE
"file", BASE
"file2/") == -1);
130 ASSERT (errno
== ENOENT
|| errno
== ENOTDIR
);
134 ASSERT (func (BASE
"file/", BASE
"file2") == -1);
135 ASSERT (errno
== ENOTDIR
);
139 ASSERT (stat (BASE
"file2", &st
) == -1);
140 ASSERT (errno
== ENOENT
);
143 { /* Simple rename. */
144 ASSERT (func (BASE
"file", BASE
"file2") == 0);
146 ASSERT (stat (BASE
"file", &st
) == -1);
147 ASSERT (errno
== ENOENT
);
148 memset (&st
, 0, sizeof st
);
149 ASSERT (stat (BASE
"file2", &st
) == 0);
150 ASSERT (st
.st_size
== 2);
152 /* Files present here:
157 ASSERT (close (creat (BASE
"file", 0600)) == 0);
159 ASSERT (func (BASE
"file2", BASE
"file/") == -1);
160 ASSERT (errno
== ENOTDIR
);
161 ASSERT (func (BASE
"file2", BASE
"file") == 0);
162 memset (&st
, 0, sizeof st
);
163 ASSERT (stat (BASE
"file", &st
) == 0);
164 ASSERT (st
.st_size
== 2);
166 ASSERT (stat (BASE
"file2", &st
) == -1);
167 ASSERT (errno
== ENOENT
);
169 /* Files present here:
176 { /* Simple rename. */
178 ASSERT (func (BASE
"dir", BASE
"dir2/") == 0);
180 ASSERT (stat (BASE
"dir", &st
) == -1);
181 ASSERT (errno
== ENOENT
);
182 ASSERT (stat (BASE
"dir2", &st
) == 0);
184 /* Files present here:
189 ASSERT (func (BASE
"dir2/", BASE
"dir") == 0);
190 ASSERT (stat (BASE
"dir", &st
) == 0);
192 ASSERT (stat (BASE
"dir2", &st
) == -1);
193 ASSERT (errno
== ENOENT
);
195 /* Files present here:
200 ASSERT (func (BASE
"dir", BASE
"dir2") == 0);
202 ASSERT (stat (BASE
"dir", &st
) == -1);
203 ASSERT (errno
== ENOENT
);
204 ASSERT (stat (BASE
"dir2", &st
) == 0);
206 /* Files present here:
210 { /* Empty onto empty. */
211 ASSERT (mkdir (BASE
"dir", 0700) == 0);
212 /* Files present here:
217 ASSERT (func (BASE
"dir2", BASE
"dir") == 0);
218 /* Files present here:
222 ASSERT (mkdir (BASE
"dir2", 0700) == 0);
223 /* Files present here:
228 ASSERT (func (BASE
"dir2", BASE
"dir/") == 0);
229 /* Files present here:
233 ASSERT (mkdir (BASE
"dir2", 0700) == 0);
234 /* Files present here:
239 ASSERT (func (BASE
"dir2/", BASE
"dir") == 0);
240 /* Files present here:
244 ASSERT (mkdir (BASE
"dir2", 0700) == 0);
246 /* Files present here:
251 { /* Empty onto full. */
252 ASSERT (close (creat (BASE
"dir/file", 0600)) == 0);
253 /* Files present here:
261 ASSERT (func (BASE
"dir2", BASE
"dir") == -1);
262 ASSERT (errno
== EEXIST
|| errno
== ENOTEMPTY
);
266 ASSERT (func (BASE
"dir2/", BASE
"dir") == -1);
267 ASSERT (errno
== EEXIST
|| errno
== ENOTEMPTY
);
271 ASSERT (func (BASE
"dir2", BASE
"dir/") == -1);
272 ASSERT (errno
== EEXIST
|| errno
== ENOTEMPTY
);
275 { /* Full onto empty. */
276 ASSERT (func (BASE
"dir", BASE
"dir2") == 0);
277 assert_nonexistent (BASE
"dir");
278 ASSERT (stat (BASE
"dir2/file", &st
) == 0);
279 /* Files present here:
284 ASSERT (mkdir (BASE
"dir", 0700) == 0);
285 /* Files present here:
292 ASSERT (func (BASE
"dir2/", BASE
"dir") == 0);
293 ASSERT (stat (BASE
"dir/file", &st
) == 0);
295 ASSERT (stat (BASE
"dir2", &st
) == -1);
296 ASSERT (errno
== ENOENT
);
298 /* Files present here:
303 ASSERT (mkdir (BASE
"dir2", 0700) == 0);
304 /* Files present here:
311 ASSERT (func (BASE
"dir", BASE
"dir2/") == 0);
312 assert_nonexistent (BASE
"dir");
313 ASSERT (stat (BASE
"dir2/file", &st
) == 0);
315 /* Files present here:
320 ASSERT (unlink (BASE
"dir2/file") == 0);
322 /* Files present here:
326 { /* Reject trailing dot. */
329 ASSERT (func (BASE
"dir2", BASE
"dir/.") == -1);
330 ASSERT (errno
== EINVAL
|| errno
== ENOENT
);
332 ASSERT (mkdir (BASE
"dir", 0700) == 0);
333 /* Files present here:
340 ASSERT (func (BASE
"dir2", BASE
"dir/.") == -1);
341 ASSERT (errno
== EINVAL
|| errno
== EBUSY
|| errno
== EISDIR
342 || errno
== ENOTEMPTY
|| errno
== EEXIST
);
346 ASSERT (func (BASE
"dir2/.", BASE
"dir") == -1);
347 ASSERT (errno
== EINVAL
|| errno
== EBUSY
|| errno
== EEXIST
);
349 ASSERT (rmdir (BASE
"dir") == 0);
350 /* Files present here:
356 ASSERT (func (BASE
"dir2", BASE
"dir/.//") == -1);
357 ASSERT (errno
== EINVAL
|| errno
== ENOENT
);
359 ASSERT (mkdir (BASE
"dir", 0700) == 0);
360 /* Files present here:
367 ASSERT (func (BASE
"dir2", BASE
"dir/.//") == -1);
368 ASSERT (errno
== EINVAL
|| errno
== EBUSY
|| errno
== EISDIR
369 || errno
== ENOTEMPTY
|| errno
== EEXIST
);
373 ASSERT (func (BASE
"dir2/.//", BASE
"dir") == -1);
374 ASSERT (errno
== EINVAL
|| errno
== EBUSY
|| errno
== EEXIST
);
376 ASSERT (rmdir (BASE
"dir2") == 0);
377 /* Files present here:
382 { /* Move into subdir. */
385 ASSERT (func (BASE
"dir", BASE
"dir/sub") == -1);
386 ASSERT (errno
== EINVAL
|| errno
== EACCES
);
390 ASSERT (stat (BASE
"dir/sub", &st
) == -1);
391 ASSERT (errno
== ENOENT
);
393 ASSERT (mkdir (BASE
"dir/sub", 0700) == 0);
394 /* Files present here:
401 ASSERT (func (BASE
"dir", BASE
"dir/sub") == -1);
402 ASSERT (errno
== EINVAL
);
403 ASSERT (stat (BASE
"dir/sub", &st
) == 0);
405 ASSERT (rmdir (BASE
"dir/sub") == 0);
408 /* Files present here:
413 /* Mixing file and directory. */
416 { /* File onto dir. */
419 ASSERT (func (BASE
"file", BASE
"dir") == -1);
420 ASSERT (errno
== EISDIR
|| errno
== ENOTDIR
);
424 ASSERT (func (BASE
"file", BASE
"dir/") == -1);
425 ASSERT (errno
== EISDIR
|| errno
== ENOTDIR
);
428 { /* Dir onto file. */
431 ASSERT (func (BASE
"dir", BASE
"file") == -1);
432 ASSERT (errno
== ENOTDIR
);
436 ASSERT (func (BASE
"dir/", BASE
"file") == -1);
437 ASSERT (errno
== ENOTDIR
);
444 { /* File onto self. */
445 ASSERT (func (BASE
"file", BASE
"file") == 0);
446 memset (&st
, 0, sizeof st
);
447 ASSERT (stat (BASE
"file", &st
) == 0);
448 ASSERT (st
.st_size
== 2);
450 /* Files present here:
454 { /* Empty dir onto self. */
455 ASSERT (func (BASE
"dir", BASE
"dir") == 0);
456 ASSERT (stat (BASE
"dir", &st
) == 0);
458 /* Files present here:
462 ASSERT (close (creat (BASE
"dir/file", 0600)) == 0);
463 /* Files present here:
468 { /* Full dir onto self. */
469 ASSERT (func (BASE
"dir", BASE
"dir") == 0);
471 ASSERT (unlink (BASE
"dir/file") == 0);
472 /* Files present here:
477 /* Not all file systems support link. Mingw doesn't have
478 reliable st_nlink on hard links, but our implementation does
479 fail with EPERM on poor file systems, and we can detect the
480 inferior stat() via st_ino. Cygwin 1.5.x copies rather than
481 links files on those file systems, but there, st_nlink and
482 st_ino are reliable. */
483 int ret
= link (BASE
"file", BASE
"file2");
486 memset (&st
, 0, sizeof st
);
487 ASSERT (stat (BASE
"file2", &st
) == 0);
488 if (st
.st_ino
&& st
.st_nlink
!= 2)
490 ASSERT (unlink (BASE
"file2") == 0);
497 /* If the device does not support hard links, errno is
498 EPERM on Linux, EOPNOTSUPP on FreeBSD. */
504 fputs ("skipping test: "
505 "hard links not supported on this file system\n",
507 ASSERT (unlink (BASE
"file") == 0);
508 ASSERT (rmdir (BASE
"dir") == 0);
517 /* Files present here:
519 {BASE}file2 (hard link to file)
522 { /* File onto hard link. */
523 ASSERT (func (BASE
"file", BASE
"file2") == 0);
524 memset (&st
, 0, sizeof st
);
525 if (stat (BASE
"file", &st
) != 0)
527 /* This can happen on NetBSD. */
528 ASSERT (errno
== ENOENT
);
529 ASSERT (link (BASE
"file2", BASE
"file") == 0);
530 ASSERT (stat (BASE
"file", &st
) == 0);
532 ASSERT (st
.st_size
== 2);
533 memset (&st
, 0, sizeof st
);
534 ASSERT (stat (BASE
"file2", &st
) == 0);
535 ASSERT (st
.st_size
== 2);
537 /* Files present here:
542 ASSERT (unlink (BASE
"file2") == 0);
543 /* Files present here:
550 if (symlink (BASE
"file", BASE
"link1"))
553 fputs ("skipping test: symlinks not supported on this file system\n",
555 ASSERT (unlink (BASE
"file") == 0);
556 ASSERT (rmdir (BASE
"dir") == 0);
559 /* Files present here:
561 {BASE}link1 -> {BASE}file
564 { /* Simple rename. */
565 ASSERT (func (BASE
"link1", BASE
"link2") == 0);
566 ASSERT (stat (BASE
"file", &st
) == 0);
568 ASSERT (lstat (BASE
"link1", &st
) == -1);
569 ASSERT (errno
== ENOENT
);
570 memset (&st
, 0, sizeof st
);
571 ASSERT (lstat (BASE
"link2", &st
) == 0);
572 ASSERT (S_ISLNK (st
.st_mode
));
574 /* Files present here:
576 {BASE}link2 -> {BASE}file
580 ASSERT (symlink (BASE
"nowhere", BASE
"link1") == 0);
581 /* Files present here:
583 {BASE}link1 -> {BASE}nowhere
584 {BASE}link2 -> {BASE}file
588 ASSERT (func (BASE
"link2", BASE
"link1") == 0);
589 memset (&st
, 0, sizeof st
);
590 ASSERT (stat (BASE
"link1", &st
) == 0);
591 ASSERT (st
.st_size
== 2);
593 ASSERT (lstat (BASE
"link2", &st
) == -1);
594 ASSERT (errno
== ENOENT
);
597 /* Files present here:
599 {BASE}link1 -> {BASE}file
602 { /* Symlink loop. */
603 ASSERT (symlink (BASE
"link2", BASE
"link2") == 0);
604 /* Files present here:
606 {BASE}link1 -> {BASE}file
607 {BASE}link2 -> {BASE}link2
611 ASSERT (func (BASE
"link2", BASE
"link2") == 0);
615 ASSERT (func (BASE
"link2/", BASE
"link2") == -1);
616 ASSERT (errno
== ELOOP
|| errno
== ENOTDIR
);
618 ASSERT (func (BASE
"link2", BASE
"link3") == 0);
619 /* Files present here:
621 {BASE}link1 -> {BASE}file
622 {BASE}link3 -> {BASE}link2
625 ASSERT (unlink (BASE
"link3") == 0);
627 /* Files present here:
629 {BASE}link1 -> {BASE}file
632 { /* Dangling link. */
633 ASSERT (symlink (BASE
"nowhere", BASE
"link2") == 0);
634 /* Files present here:
636 {BASE}link1 -> {BASE}file
637 {BASE}link2 -> {BASE}nowhere
641 ASSERT (func (BASE
"link2", BASE
"link3") == 0);
643 ASSERT (lstat (BASE
"link2", &st
) == -1);
644 ASSERT (errno
== ENOENT
);
645 memset (&st
, 0, sizeof st
);
646 ASSERT (lstat (BASE
"link3", &st
) == 0);
649 /* Files present here:
651 {BASE}link1 -> {BASE}file
652 {BASE}link3 -> {BASE}nowhere
655 { /* Trailing slash on dangling. */
658 ASSERT (func (BASE
"link3/", BASE
"link2") == -1);
659 ASSERT (errno
== ENOENT
|| errno
== ENOTDIR
);
663 ASSERT (func (BASE
"link3", BASE
"link2/") == -1);
664 ASSERT (errno
== ENOENT
|| errno
== ENOTDIR
);
668 ASSERT (lstat (BASE
"link2", &st
) == -1);
669 ASSERT (errno
== ENOENT
);
671 memset (&st
, 0, sizeof st
);
672 ASSERT (lstat (BASE
"link3", &st
) == 0);
674 /* Files present here:
676 {BASE}link1 -> {BASE}file
677 {BASE}link3 -> {BASE}nowhere
680 { /* Trailing slash on link to file. */
683 ASSERT (func (BASE
"link1/", BASE
"link2") == -1);
684 ASSERT (errno
== ENOTDIR
);
688 ASSERT (func (BASE
"link1", BASE
"link3/") == -1);
689 ASSERT (errno
== ENOENT
|| errno
== ENOTDIR
);
692 /* Files present here:
694 {BASE}link1 -> {BASE}file
695 {BASE}link3 -> {BASE}nowhere
699 /* Mixing symlink and file. */
701 { /* File onto link. */
702 ASSERT (close (creat (BASE
"file2", 0600)) == 0);
703 /* Files present here:
706 {BASE}link1 -> {BASE}file
707 {BASE}link3 -> {BASE}nowhere
711 ASSERT (func (BASE
"file2", BASE
"link3") == 0);
713 ASSERT (stat (BASE
"file2", &st
) == -1);
714 ASSERT (errno
== ENOENT
);
715 memset (&st
, 0, sizeof st
);
716 ASSERT (lstat (BASE
"link3", &st
) == 0);
717 ASSERT (S_ISREG (st
.st_mode
));
719 /* Files present here:
721 {BASE}link1 -> {BASE}file
725 ASSERT (unlink (BASE
"link3") == 0);
727 /* Files present here:
729 {BASE}link1 -> {BASE}file
732 { /* Link onto file. */
733 ASSERT (symlink (BASE
"nowhere", BASE
"link2") == 0);
734 /* Files present here:
736 {BASE}link1 -> {BASE}file
737 {BASE}link2 -> {BASE}nowhere
740 ASSERT (close (creat (BASE
"file2", 0600)) == 0);
741 /* Files present here:
744 {BASE}link1 -> {BASE}file
745 {BASE}link2 -> {BASE}nowhere
749 ASSERT (func (BASE
"link2", BASE
"file2") == 0);
751 ASSERT (lstat (BASE
"link2", &st
) == -1);
752 ASSERT (errno
== ENOENT
);
753 memset (&st
, 0, sizeof st
);
754 ASSERT (lstat (BASE
"file2", &st
) == 0);
755 ASSERT (S_ISLNK (st
.st_mode
));
757 /* Files present here:
759 {BASE}file2 -> {BASE}nowhere
760 {BASE}link1 -> {BASE}file
763 ASSERT (unlink (BASE
"file2") == 0);
765 /* Files present here:
767 {BASE}link1 -> {BASE}file
770 { /* Trailing slash. */
773 ASSERT (func (BASE
"file/", BASE
"link1") == -1);
774 ASSERT (errno
== ENOTDIR
);
778 ASSERT (func (BASE
"file", BASE
"link1/") == -1);
779 ASSERT (errno
== ENOTDIR
|| errno
== ENOENT
);
783 ASSERT (func (BASE
"link1/", BASE
"file") == -1);
784 ASSERT (errno
== ENOTDIR
);
788 ASSERT (func (BASE
"link1", BASE
"file/") == -1);
789 ASSERT (errno
== ENOTDIR
|| errno
== ENOENT
);
790 memset (&st
, 0, sizeof st
);
791 ASSERT (lstat (BASE
"file", &st
) == 0);
792 ASSERT (S_ISREG (st
.st_mode
));
793 memset (&st
, 0, sizeof st
);
794 ASSERT (lstat (BASE
"link1", &st
) == 0);
795 ASSERT (S_ISLNK (st
.st_mode
));
798 /* Files present here:
800 {BASE}link1 -> {BASE}file
804 /* Mixing symlink and directory. */
806 { /* Directory onto link. */
809 ASSERT (func (BASE
"dir", BASE
"link1") == -1);
810 ASSERT (errno
== ENOTDIR
);
814 ASSERT (func (BASE
"dir/", BASE
"link1") == -1);
815 ASSERT (errno
== ENOTDIR
);
819 ASSERT (func (BASE
"dir", BASE
"link1/") == -1);
820 ASSERT (errno
== ENOTDIR
);
823 { /* Link onto directory. */
826 ASSERT (func (BASE
"link1", BASE
"dir") == -1);
827 ASSERT (errno
== EISDIR
|| errno
== ENOTDIR
);
831 ASSERT (func (BASE
"link1", BASE
"dir/") == -1);
832 ASSERT (errno
== EISDIR
|| errno
== ENOTDIR
);
836 ASSERT (func (BASE
"link1/", BASE
"dir") == -1);
837 ASSERT (errno
== ENOTDIR
);
838 memset (&st
, 0, sizeof st
);
839 ASSERT (lstat (BASE
"link1", &st
) == 0);
840 ASSERT (S_ISLNK (st
.st_mode
));
841 memset (&st
, 0, sizeof st
);
842 ASSERT (lstat (BASE
"dir", &st
) == 0);
843 ASSERT (S_ISDIR (st
.st_mode
));
846 /* Files present here:
848 {BASE}link1 -> {BASE}file
852 /* POSIX requires rename("link-to-dir/","other") to rename "dir" and
853 leave "link-to-dir" dangling, but GNU rejects this. POSIX
854 requires rename("dir","dangling/") to create the directory so
855 that "dangling/" now resolves, but GNU rejects this. While we
856 prefer GNU behavior, we don't enforce it. However, we do test
857 that the system either follows POSIX in both cases, or follows
861 ASSERT (symlink (BASE
"dir2", BASE
"link2") == 0);
862 /* Files present here:
864 {BASE}link1 -> {BASE}file
865 {BASE}link2 -> {BASE}dir2
869 result
= func (BASE
"dir", BASE
"link2/");
874 ASSERT (lstat (BASE
"dir", &st
) == -1);
875 ASSERT (errno
== ENOENT
);
876 memset (&st
, 0, sizeof st
);
877 ASSERT (lstat (BASE
"dir2", &st
) == 0);
878 ASSERT (S_ISDIR (st
.st_mode
));
879 memset (&st
, 0, sizeof st
);
880 ASSERT (lstat (BASE
"link2", &st
) == 0);
881 ASSERT (S_ISLNK (st
.st_mode
));
882 /* Files present here:
884 {BASE}link1 -> {BASE}file
885 {BASE}link2 -> {BASE}dir2
889 ASSERT (func (BASE
"link2/", BASE
"dir") == 0);
890 memset (&st
, 0, sizeof st
);
891 ASSERT (lstat (BASE
"dir", &st
) == 0);
892 ASSERT (S_ISDIR (st
.st_mode
));
894 ASSERT (lstat (BASE
"dir2", &st
) == -1);
895 ASSERT (errno
== ENOENT
);
896 memset (&st
, 0, sizeof st
);
897 ASSERT (lstat (BASE
"link2", &st
) == 0);
898 ASSERT (S_ISLNK (st
.st_mode
));
904 ASSERT (result
== -1);
905 ASSERT (errno
== ENOTDIR
);
906 memset (&st
, 0, sizeof st
);
907 ASSERT (lstat (BASE
"dir", &st
) == 0);
908 ASSERT (S_ISDIR (st
.st_mode
));
910 ASSERT (lstat (BASE
"dir2", &st
) == -1);
911 ASSERT (errno
== ENOENT
);
912 memset (&st
, 0, sizeof st
);
913 ASSERT (lstat (BASE
"link2", &st
) == 0);
914 ASSERT (S_ISLNK (st
.st_mode
));
915 ASSERT (unlink (BASE
"link2") == 0);
916 ASSERT (symlink (BASE
"dir", BASE
"link2") == 0);
917 /* Files present here:
919 {BASE}link1 -> {BASE}file
920 {BASE}link2 -> {BASE}dir
923 errno
= 0; /* OpenBSD notices that link2/ and dir are the same. */
924 result
= func (BASE
"link2/", BASE
"dir");
925 if (result
) /* GNU/Linux rejects attempts to use link2/. */
927 ASSERT (result
== -1);
928 ASSERT (errno
== ENOTDIR
|| errno
== EISDIR
);
930 memset (&st
, 0, sizeof st
);
931 ASSERT (lstat (BASE
"dir", &st
) == 0);
932 ASSERT (S_ISDIR (st
.st_mode
));
934 ASSERT (lstat (BASE
"dir2", &st
) == -1);
935 ASSERT (errno
== ENOENT
);
936 memset (&st
, 0, sizeof st
);
937 ASSERT (lstat (BASE
"link2", &st
) == 0);
938 ASSERT (S_ISLNK (st
.st_mode
));
941 /* Files present here:
943 {BASE}link1 -> {BASE}file
944 {BASE}link2 -> {BASE}dir or {BASE}dir2
949 ASSERT (unlink (BASE
"file") == 0);
950 ASSERT (rmdir (BASE
"dir") == 0);
951 ASSERT (unlink (BASE
"link1") == 0);
952 ASSERT (unlink (BASE
"link2") == 0);