1 /* Test of mkdir() 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 <https://www.gnu.org/licenses/>. */
17 /* This file is designed to test both mkdir(a,b) and
18 mkdirat(AT_FDCWD,a,b). FUNC is the function to test. Assumes that
19 BASE and ASSERT are already defined, and that appropriate headers
20 are already included. If PRINT, warn before skipping tests with
21 status 77 when symlinks are unsupported. */
24 test_mkdir (int (*func
) (char const *, mode_t
), bool print
)
26 /* Test basic error handling. */
27 ASSERT (close (creat (BASE
"file", 0600)) == 0);
29 ASSERT (func (BASE
"file", 0700) == -1);
30 ASSERT (errno
== EEXIST
);
32 ASSERT (func (BASE
"file/", 0700) == -1);
33 ASSERT (errno
== ENOTDIR
|| errno
== EEXIST
);
35 ASSERT (func (BASE
"file/dir", 0700) == -1);
36 ASSERT (errno
== ENOTDIR
|| errno
== ENOENT
|| errno
== EOPNOTSUPP
);
37 ASSERT (unlink (BASE
"file") == 0);
39 ASSERT (func ("", 0700) == -1);
40 ASSERT (errno
== ENOENT
);
42 ASSERT (func (BASE
"dir/sub", 0700) == -1);
43 ASSERT (errno
== ENOENT
);
45 ASSERT (func (BASE
"dir/.", 0700) == -1);
46 ASSERT (errno
== ENOENT
);
48 ASSERT (func (BASE
"dir/.//", 0700) == -1);
49 ASSERT (errno
== ENOENT
);
51 /* Test trailing slash handling. */
52 ASSERT (func (BASE
"dir", 0700) == 0);
54 ASSERT (func (BASE
"dir", 0700) == -1);
55 ASSERT (errno
== EEXIST
);
56 ASSERT (rmdir (BASE
"dir") == 0);
57 ASSERT (func (BASE
"dir/", 0700) == 0);
59 ASSERT (func (BASE
"dir/", 0700) == -1);
60 ASSERT (errno
== EEXIST
);
61 ASSERT (rmdir (BASE
"dir") == 0);
63 /* Test symlink behavior. POSIX requires the creation of
64 directories through a dangling symlink with trailing slash, but
65 GNU does not yet implement that, so we support either behavior
67 if (symlink (BASE
"dir", BASE
"link"))
70 fputs ("skipping test: symlinks not supported on this file system\n",
75 ASSERT (func (BASE
"link", 0700) == -1);
76 ASSERT (errno
== EEXIST
);
80 result
= func (BASE
"link/", 0700);
82 ASSERT (rmdir (BASE
"dir") == 0);
85 ASSERT (result
== -1);
86 ASSERT (errno
== EEXIST
);
88 ASSERT (rmdir (BASE
"dir") == -1);
89 ASSERT (errno
== ENOENT
);
93 ASSERT (func (BASE
"link/.", 0700) == -1);
94 ASSERT (errno
== ENOENT
);
95 ASSERT (unlink (BASE
"link") == 0);