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 ASSERT(expr) \
35 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
42 #define BASE "test-mkdirat.t"
44 #include "test-mkdir.h"
46 static int dfd = AT_FDCWD;
48 /* Wrapper to test mkdirat like mkdir. */
50 do_mkdir (char const *name, mode_t mode)
52 return mkdirat (dfd, name, mode);
60 /* Clean up any trash from prior testsuite runs. */
61 ASSERT (system ("rm -rf " BASE "*") == 0);
63 /* Test basic mkdir functionality. */
64 result = test_mkdir (do_mkdir, false);
65 dfd = open (".", O_RDONLY);
67 ASSERT (test_mkdir (do_mkdir, false) == result);
69 /* Tests specific to mkdirat. */
70 ASSERT (mkdirat (dfd, BASE "dir1", 0700) == 0);
71 ASSERT (chdir (BASE "dir1") == 0);
72 ASSERT (close (dfd) == 0);
73 dfd = open ("..", O_RDONLY);
75 ASSERT (mkdirat (dfd, BASE "dir2", 0700) == 0);
76 ASSERT (close (dfd) == 0);
78 ASSERT (mkdirat (dfd, BASE "dir3", 0700) == -1);
79 ASSERT (errno == EBADF);
80 dfd = open ("/dev/null", O_RDONLY);
83 ASSERT (mkdirat (dfd, "dir3", 0700) == -1);
84 ASSERT (errno == ENOTDIR);
85 ASSERT (close (dfd) == 0);
86 ASSERT (chdir ("..") == 0);
87 ASSERT (rmdir (BASE "dir1") == 0);
88 ASSERT (rmdir (BASE "dir2") == 0);