2 Copyright (C) 2009 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 /* Written by Eric Blake <ebb9@byu.net>, 2009. */
30 # define symlink(a,b) (-1)
33 #define ASSERT(expr) \
38 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
45 #define BASE "test-rmdir.t"
50 /* Remove any leftovers from a previous partial run. */
51 ASSERT (system ("rm -rf " BASE "*") == 0);
54 ASSERT (mkdir (BASE "dir", 0700) == 0);
55 ASSERT (close (creat (BASE "dir/file", 0600)) == 0);
57 /* Basic error conditions. */
59 ASSERT (rmdir ("") == -1);
60 ASSERT (errno == ENOENT);
62 ASSERT (rmdir (BASE "nosuch") == -1);
63 ASSERT (errno == ENOENT);
65 ASSERT (rmdir (BASE "nosuch/") == -1);
66 ASSERT (errno == ENOENT);
68 ASSERT (rmdir (".") == -1);
69 ASSERT (errno == EINVAL || errno == EBUSY);
70 /* Resulting errno after ".." or "/" is too varied to test; it is
71 reasonable to see any of EINVAL, EBUSY, EEXIST, ENOTEMPTY,
73 ASSERT (rmdir ("..") == -1);
74 ASSERT (rmdir ("/") == -1);
75 ASSERT (rmdir ("///") == -1);
77 ASSERT (rmdir (BASE "dir/file/") == -1);
78 ASSERT (errno == ENOTDIR);
80 /* Non-empty directory. */
82 ASSERT (rmdir (BASE "dir") == -1);
83 ASSERT (errno == EEXIST || errno == ENOTEMPTY);
87 ASSERT (rmdir (BASE "dir/file") == -1);
88 ASSERT (errno == ENOTDIR);
90 /* Empty directory. */
91 ASSERT (unlink (BASE "dir/file") == 0);
93 ASSERT (rmdir (BASE "dir/./") == -1);
94 ASSERT (errno == EINVAL || errno == EBUSY);
95 ASSERT (rmdir (BASE "dir") == 0);
97 /* Test symlink behavior. Specifying trailing slash should remove
98 referent directory (POSIX), or cause ENOTDIR failure (Linux), but
99 not touch symlink. We prefer the Linux behavior for its
100 intuitiveness (especially compared to rmdir("symlink-to-file/")),
101 but not enough to penalize POSIX systems with an rpl_rmdir. */
102 if (symlink (BASE "dir", BASE "link") != 0)
104 fputs ("skipping test: symlinks not supported on this filesystem\n",
108 ASSERT (mkdir (BASE "dir", 0700) == 0);
110 if (rmdir (BASE "link/") == 0)
114 ASSERT (stat (BASE "link", &st) == -1);
115 ASSERT (errno == ENOENT);
119 ASSERT (errno == ENOTDIR);
120 ASSERT (rmdir (BASE "dir") == 0);
122 ASSERT (unlink (BASE "link") == 0);