Mercurial > hg > octave-lojdl > gnulib-hg
annotate tests/test-unlinkat.c @ 17460:d11431703671
autoupdate
author | Karl Berry <karl@freefriends.org> |
---|---|
date | Fri, 09 Aug 2013 08:03:30 -0700 |
parents | 3a09cc104f4c |
children |
rev | line source |
---|---|
11995
5767a52927aa
openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
1 /* Tests of unlinkat. |
17249
e542fd46ad6f
maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents:
16201
diff
changeset
|
2 Copyright (C) 2009-2013 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 | 23 #include "signature.h" |
24 SIGNATURE_CHECK (unlinkat, int, (int, char const *, int)); | |
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 |
15287
223683be3038
openat, fdopendir tests: Fix link errors.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
33 #include "progname.h" |
12043
fc84db4ef49d
test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents:
11995
diff
changeset
|
34 #include "unlinkdir.h" |
12842
b2bf8684a2db
tests: silence warning about system return
Eric Blake <ebb9@byu.net>
parents:
12559
diff
changeset
|
35 #include "ignore-value.h" |
12496
a48d3d749ca5
Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents:
12489
diff
changeset
|
36 #include "macros.h" |
11995
5767a52927aa
openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
37 |
5767a52927aa
openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
38 #define BASE "test-unlinkat.t" |
5767a52927aa
openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
39 |
5767a52927aa
openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
40 #include "test-rmdir.h" |
12043
fc84db4ef49d
test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents:
11995
diff
changeset
|
41 #include "test-unlink.h" |
fc84db4ef49d
test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents:
11995
diff
changeset
|
42 |
fc84db4ef49d
test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents:
11995
diff
changeset
|
43 static int dfd = AT_FDCWD; |
11995
5767a52927aa
openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
44 |
5767a52927aa
openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
45 /* Wrapper around unlinkat to test rmdir behavior. */ |
5767a52927aa
openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
46 static int |
5767a52927aa
openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
47 rmdirat (char const *name) |
5767a52927aa
openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
48 { |
12043
fc84db4ef49d
test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents:
11995
diff
changeset
|
49 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
|
50 } |
fc84db4ef49d
test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents:
11995
diff
changeset
|
51 |
fc84db4ef49d
test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents:
11995
diff
changeset
|
52 /* 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
|
53 static int |
fc84db4ef49d
test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents:
11995
diff
changeset
|
54 unlinker (char const *name) |
fc84db4ef49d
test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents:
11995
diff
changeset
|
55 { |
fc84db4ef49d
test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents:
11995
diff
changeset
|
56 return unlinkat (dfd, name, 0); |
11995
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 |
5767a52927aa
openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
59 int |
15287
223683be3038
openat, fdopendir tests: Fix link errors.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
60 main (int argc _GL_UNUSED, char *argv[]) |
11995
5767a52927aa
openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
61 { |
12043
fc84db4ef49d
test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents:
11995
diff
changeset
|
62 /* 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
|
63 int result1; |
fc84db4ef49d
test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents:
11995
diff
changeset
|
64 int result2; |
12517
013b270a78b9
tests: don't require debug system() to pass
Eric Blake <ebb9@byu.net>
parents:
12496
diff
changeset
|
65 |
15287
223683be3038
openat, fdopendir tests: Fix link errors.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
66 set_program_name (argv[0]); |
223683be3038
openat, fdopendir tests: Fix link errors.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
67 |
12517
013b270a78b9
tests: don't require debug system() to pass
Eric Blake <ebb9@byu.net>
parents:
12496
diff
changeset
|
68 /* 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
|
69 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
|
70 |
15700
bbc06c8e298f
openat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
15287
diff
changeset
|
71 /* Test behaviour for invalid file descriptors. */ |
bbc06c8e298f
openat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
15287
diff
changeset
|
72 { |
bbc06c8e298f
openat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
15287
diff
changeset
|
73 errno = 0; |
bbc06c8e298f
openat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
15287
diff
changeset
|
74 ASSERT (unlinkat (-1, "foo", 0) == -1); |
bbc06c8e298f
openat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
15287
diff
changeset
|
75 ASSERT (errno == EBADF); |
bbc06c8e298f
openat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
15287
diff
changeset
|
76 } |
bbc06c8e298f
openat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
15287
diff
changeset
|
77 { |
17295
3a09cc104f4c
tests: don't assume fd 99 is closed
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
78 close (99); |
15700
bbc06c8e298f
openat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
15287
diff
changeset
|
79 errno = 0; |
bbc06c8e298f
openat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
15287
diff
changeset
|
80 ASSERT (unlinkat (99, "foo", 0) == -1); |
bbc06c8e298f
openat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
15287
diff
changeset
|
81 ASSERT (errno == EBADF); |
bbc06c8e298f
openat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
15287
diff
changeset
|
82 } |
bbc06c8e298f
openat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
15287
diff
changeset
|
83 |
12043
fc84db4ef49d
test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents:
11995
diff
changeset
|
84 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
|
85 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
|
86 ASSERT (result1 == result2); |
fc84db4ef49d
test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents:
11995
diff
changeset
|
87 dfd = open (".", O_RDONLY); |
fc84db4ef49d
test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents:
11995
diff
changeset
|
88 ASSERT (0 <= dfd); |
fc84db4ef49d
test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents:
11995
diff
changeset
|
89 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
|
90 ASSERT (result1 == result2); |
fc84db4ef49d
test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents:
11995
diff
changeset
|
91 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
|
92 ASSERT (result1 == result2); |
fc84db4ef49d
test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents:
11995
diff
changeset
|
93 ASSERT (close (dfd) == 0); |
fc84db4ef49d
test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents:
11995
diff
changeset
|
94 if (result1 == 77) |
12146
e076a06bae48
maint: prefer 'file system' over 'filesystem'
Eric Blake <ebb9@byu.net>
parents:
12057
diff
changeset
|
95 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
|
96 stderr); |
12043
fc84db4ef49d
test-unlinkat: enhance test, to expose Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents:
11995
diff
changeset
|
97 return result1; |
11995
5767a52927aa
openat-tests: ensure unlinkat behaves like rmdir
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
98 } |