/* Tests of rmdir.
- Copyright (C) 2009 Free Software Foundation, Inc.
+ Copyright (C) 2009, 2010 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include <unistd.h>
+#include "signature.h"
+SIGNATURE_CHECK (rmdir, int, (char const *));
+
#include <fcntl.h>
#include <errno.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
-#if !HAVE_SYMLINK
-# define symlink(a,b) (-1)
-#endif
-
-#define ASSERT(expr) \
- do \
- { \
- if (!(expr)) \
- { \
- fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
- fflush (stderr); \
- abort (); \
- } \
- } \
- while (0)
+#include "ignore-value.h"
+#include "macros.h"
#define BASE "test-rmdir.t"
+#include "test-rmdir.h"
+
int
-main ()
+main (void)
{
/* Remove any leftovers from a previous partial run. */
- ASSERT (system ("rm -rf " BASE "*") == 0);
-
- /* Setup. */
- ASSERT (mkdir (BASE "dir", 0700) == 0);
- ASSERT (close (creat (BASE "dir/file", 0600)) == 0);
-
- /* Basic error conditions. */
- errno = 0;
- ASSERT (rmdir ("") == -1);
- ASSERT (errno == ENOENT);
- errno = 0;
- ASSERT (rmdir (BASE "nosuch") == -1);
- ASSERT (errno == ENOENT);
- errno = 0;
- ASSERT (rmdir (BASE "nosuch/") == -1);
- ASSERT (errno == ENOENT);
- errno = 0;
- ASSERT (rmdir (".") == -1);
- ASSERT (errno == EINVAL || errno == EBUSY);
- /* Resulting errno after ".." or "/" is too varied to test; it is
- reasonable to see any of EINVAL, EBUSY, EEXIST, ENOTEMPTY,
- EACCES, EPERM. */
- ASSERT (rmdir ("..") == -1);
- ASSERT (rmdir ("/") == -1);
- ASSERT (rmdir ("///") == -1);
- errno = 0;
- ASSERT (rmdir (BASE "dir/file/") == -1);
- ASSERT (errno == ENOTDIR);
-
- /* Non-empty directory. */
- errno = 0;
- ASSERT (rmdir (BASE "dir") == -1);
- ASSERT (errno == EEXIST || errno == ENOTEMPTY);
-
- /* Non-directory. */
- errno = 0;
- ASSERT (rmdir (BASE "dir/file") == -1);
- ASSERT (errno == ENOTDIR);
-
- /* Empty directory. */
- ASSERT (unlink (BASE "dir/file") == 0);
- errno = 0;
- ASSERT (rmdir (BASE "dir/./") == -1);
- ASSERT (errno == EINVAL || errno == EBUSY);
- ASSERT (rmdir (BASE "dir") == 0);
-
- /* Test symlink behavior. Specifying trailing slash should remove
- referent directory (POSIX), or cause ENOTDIR failure (Linux), but
- not touch symlink. We prefer the Linux behavior for its
- intuitiveness (especially compared to rmdir("symlink-to-file/")),
- but not enough to penalize POSIX systems with an rpl_rmdir. */
- if (symlink (BASE "dir", BASE "link") != 0)
- {
- fputs ("skipping test: symlinks not supported on this filesystem\n",
- stderr);
- return 77;
- }
- ASSERT (mkdir (BASE "dir", 0700) == 0);
- errno = 0;
- if (rmdir (BASE "link/") == 0)
- {
- struct stat st;
- errno = 0;
- ASSERT (stat (BASE "link", &st) == -1);
- ASSERT (errno == ENOENT);
- }
- else
- {
- ASSERT (errno == ENOTDIR);
- ASSERT (rmdir (BASE "dir") == 0);
- }
- ASSERT (unlink (BASE "link") == 0);
+ ignore_value (system ("rm -rf " BASE "*"));
- return 0;
+ return test_rmdir_func (rmdir, true);
}