annotate tests/test-unlinkat.c @ 14079:97fc9a21a8fb

maint: update almost all copyright ranges to include 2011 Run the new "make update-copyright" rule.
author Jim Meyering <meyering@redhat.com>
date Sat, 01 Jan 2011 20:17:23 +0100
parents b2bf8684a2db
children 223683be3038
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11995
5767a52927aa openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff changeset
1 /* Tests of unlinkat.
14079
97fc9a21a8fb maint: update almost all copyright ranges to include 2011
Jim Meyering <meyering@redhat.com>
parents: 12842
diff changeset
2 Copyright (C) 2009-2011 Free Software Foundation, Inc.
11995
5767a52927aa openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff changeset
3
5767a52927aa openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
5767a52927aa openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
5767a52927aa openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
5767a52927aa openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff changeset
7 (at your option) any later version.
5767a52927aa openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff changeset
8
5767a52927aa openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
5767a52927aa openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
5767a52927aa openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5767a52927aa openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff changeset
12 GNU General Public License for more details.
5767a52927aa openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff changeset
13
5767a52927aa openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
5767a52927aa openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
5767a52927aa openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff changeset
16
5767a52927aa openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff changeset
17 /* Written by Eric Blake <ebb9@byu.net>, 2009. */
5767a52927aa openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff changeset
18
5767a52927aa openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff changeset
19 #include <config.h>
5767a52927aa openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff changeset
20
5767a52927aa openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff changeset
21 #include <unistd.h>
5767a52927aa openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff changeset
22
12489
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12421
diff changeset
23 #include "signature.h"
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12421
diff changeset
24 SIGNATURE_CHECK (unlinkat, int, (int, char const *, int));
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12421
diff changeset
25
11995
5767a52927aa openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff changeset
26 #include <fcntl.h>
5767a52927aa openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff changeset
27 #include <errno.h>
12043
fc84db4ef49d test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 11995
diff changeset
28 #include <stdbool.h>
11995
5767a52927aa openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff changeset
29 #include <stdio.h>
5767a52927aa openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff changeset
30 #include <stdlib.h>
5767a52927aa openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff changeset
31 #include <sys/stat.h>
5767a52927aa openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff changeset
32
12043
fc84db4ef49d test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 11995
diff changeset
33 #include "unlinkdir.h"
12842
b2bf8684a2db tests: silence warning about system return
Eric Blake <ebb9@byu.net>
parents: 12559
diff changeset
34 #include "ignore-value.h"
12496
a48d3d749ca5 Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents: 12489
diff changeset
35 #include "macros.h"
11995
5767a52927aa openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff changeset
36
5767a52927aa openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff changeset
37 #define BASE "test-unlinkat.t"
5767a52927aa openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff changeset
38
5767a52927aa openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff changeset
39 #include "test-rmdir.h"
12043
fc84db4ef49d test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 11995
diff changeset
40 #include "test-unlink.h"
fc84db4ef49d test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 11995
diff changeset
41
fc84db4ef49d test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 11995
diff changeset
42 static int dfd = AT_FDCWD;
11995
5767a52927aa openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff changeset
43
5767a52927aa openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff changeset
44 /* Wrapper around unlinkat to test rmdir behavior. */
5767a52927aa openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff changeset
45 static int
5767a52927aa openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff changeset
46 rmdirat (char const *name)
5767a52927aa openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff changeset
47 {
12043
fc84db4ef49d test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 11995
diff changeset
48 return unlinkat (dfd, name, AT_REMOVEDIR);
fc84db4ef49d test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 11995
diff changeset
49 }
fc84db4ef49d test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 11995
diff changeset
50
fc84db4ef49d test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 11995
diff changeset
51 /* Wrapper around unlinkat to test unlink behavior. */
fc84db4ef49d test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 11995
diff changeset
52 static int
fc84db4ef49d test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 11995
diff changeset
53 unlinker (char const *name)
fc84db4ef49d test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 11995
diff changeset
54 {
fc84db4ef49d test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 11995
diff changeset
55 return unlinkat (dfd, name, 0);
11995
5767a52927aa openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff changeset
56 }
5767a52927aa openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff changeset
57
5767a52927aa openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff changeset
58 int
12197
e45d9bb2233e tests: avoid several compiler warnings
Eric Blake <ebb9@byu.net>
parents: 12146
diff changeset
59 main (void)
11995
5767a52927aa openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff changeset
60 {
12043
fc84db4ef49d test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 11995
diff changeset
61 /* FIXME: Add tests of fd other than ".". */
fc84db4ef49d test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 11995
diff changeset
62 int result1;
fc84db4ef49d test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 11995
diff changeset
63 int result2;
12517
013b270a78b9 tests: don't require debug system() to pass
Eric Blake <ebb9@byu.net>
parents: 12496
diff changeset
64
013b270a78b9 tests: don't require debug system() to pass
Eric Blake <ebb9@byu.net>
parents: 12496
diff changeset
65 /* Remove any leftovers from a previous partial run. */
12842
b2bf8684a2db tests: silence warning about system return
Eric Blake <ebb9@byu.net>
parents: 12559
diff changeset
66 ignore_value (system ("rm -rf " BASE "*"));
12517
013b270a78b9 tests: don't require debug system() to pass
Eric Blake <ebb9@byu.net>
parents: 12496
diff changeset
67
12043
fc84db4ef49d test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 11995
diff changeset
68 result1 = test_rmdir_func (rmdirat, false);
fc84db4ef49d test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 11995
diff changeset
69 result2 = test_unlink_func (unlinker, false);
fc84db4ef49d test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 11995
diff changeset
70 ASSERT (result1 == result2);
fc84db4ef49d test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 11995
diff changeset
71 dfd = open (".", O_RDONLY);
fc84db4ef49d test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 11995
diff changeset
72 ASSERT (0 <= dfd);
fc84db4ef49d test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 11995
diff changeset
73 result2 = test_rmdir_func (rmdirat, false);
fc84db4ef49d test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 11995
diff changeset
74 ASSERT (result1 == result2);
fc84db4ef49d test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 11995
diff changeset
75 result2 = test_unlink_func (unlinker, false);
fc84db4ef49d test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 11995
diff changeset
76 ASSERT (result1 == result2);
fc84db4ef49d test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 11995
diff changeset
77 ASSERT (close (dfd) == 0);
fc84db4ef49d test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 11995
diff changeset
78 if (result1 == 77)
12146
e076a06bae48 maint: prefer 'file system' over 'filesystem'
Eric Blake <ebb9@byu.net>
parents: 12057
diff changeset
79 fputs ("skipping test: symlinks not supported on this file system\n",
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12197
diff changeset
80 stderr);
12043
fc84db4ef49d test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 11995
diff changeset
81 return result1;
11995
5767a52927aa openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff changeset
82 }