Mercurial > gnulib
annotate tests/test-fchownat.c @ 40196:e63f5d3edab5
relocatable-prog: Update documentation.
* doc/relocatable-maint.texi (Supporting Relocation): Update to match
the recent changes.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sun, 24 Feb 2019 01:49:15 +0100 |
parents | b06060465f09 |
children |
rev | line source |
---|---|
12291 | 1 /* Tests of fchownat. |
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
2 Copyright (C) 2009-2019 Free Software Foundation, Inc. |
12291 | 3 |
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. | |
8 | |
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. | |
13 | |
14 You should have received a copy of the GNU General Public License | |
19190 | 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
12291 | 16 |
17 /* Written by Eric Blake <ebb9@byu.net>, 2009. */ | |
18 | |
19 #include <config.h> | |
20 | |
21 #include <unistd.h> | |
22 | |
12489 | 23 #include "signature.h" |
24 SIGNATURE_CHECK (fchownat, int, (int, char const *, uid_t, gid_t, int)); | |
25 | |
12291 | 26 #include <fcntl.h> |
27 #include <errno.h> | |
28 #include <stdbool.h> | |
29 #include <stdio.h> | |
30 #include <stdlib.h> | |
31 #include <sys/stat.h> | |
32 | |
33 #include "mgetgroups.h" | |
34 #include "openat.h" | |
35 #include "stat-time.h" | |
12842
b2bf8684a2db
tests: silence warning about system return
Eric Blake <ebb9@byu.net>
parents:
12559
diff
changeset
|
36 #include "ignore-value.h" |
12496
a48d3d749ca5
Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents:
12489
diff
changeset
|
37 #include "macros.h" |
12291 | 38 |
39 #define BASE "test-fchownat.t" | |
40 | |
41 #include "test-chown.h" | |
42 #include "test-lchown.h" | |
43 | |
44 static int dfd = AT_FDCWD; | |
45 | |
46 /* Wrapper around fchownat to test chown behavior. */ | |
47 static int | |
48 do_chown (char const *name, uid_t user, gid_t group) | |
49 { | |
50 return chownat (dfd, name, user, group); | |
51 } | |
52 | |
53 /* Wrapper around fchownat to test lchown behavior. */ | |
54 static int | |
55 do_lchown (char const *name, uid_t user, gid_t group) | |
56 { | |
57 return lchownat (dfd, name, user, group); | |
58 } | |
59 | |
60 int | |
15287
223683be3038
openat, fdopendir tests: Fix link errors.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
61 main (int argc _GL_UNUSED, char *argv[]) |
12291 | 62 { |
63 int result1; /* Skip because of no chown/symlink support. */ | |
64 int result2; /* Skip because of no lchown support. */ | |
65 | |
66 /* Clean up any trash from prior testsuite runs. */ | |
12842
b2bf8684a2db
tests: silence warning about system return
Eric Blake <ebb9@byu.net>
parents:
12559
diff
changeset
|
67 ignore_value (system ("rm -rf " BASE "*")); |
12291 | 68 |
15700
bbc06c8e298f
openat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
15287
diff
changeset
|
69 /* Test behaviour for invalid file descriptors. */ |
bbc06c8e298f
openat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
15287
diff
changeset
|
70 { |
bbc06c8e298f
openat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
15287
diff
changeset
|
71 errno = 0; |
bbc06c8e298f
openat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
15287
diff
changeset
|
72 ASSERT (fchownat (-1, "foo", getuid (), getgid (), 0) == -1); |
bbc06c8e298f
openat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
15287
diff
changeset
|
73 ASSERT (errno == EBADF); |
bbc06c8e298f
openat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
15287
diff
changeset
|
74 } |
bbc06c8e298f
openat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
15287
diff
changeset
|
75 { |
17292
3a09cc104f4c
tests: don't assume fd 99 is closed
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
76 close (99); |
15700
bbc06c8e298f
openat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
15287
diff
changeset
|
77 errno = 0; |
bbc06c8e298f
openat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
15287
diff
changeset
|
78 ASSERT (fchownat (99, "foo", getuid (), getgid (), 0) == -1); |
bbc06c8e298f
openat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
15287
diff
changeset
|
79 ASSERT (errno == EBADF); |
bbc06c8e298f
openat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
15287
diff
changeset
|
80 } |
bbc06c8e298f
openat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
15287
diff
changeset
|
81 |
12291 | 82 /* Basic tests. */ |
83 result1 = test_chown (do_chown, true); | |
84 result2 = test_lchown (do_lchown, result1 == 0); | |
85 dfd = open (".", O_RDONLY); | |
86 ASSERT (0 <= dfd); | |
87 ASSERT (test_chown (do_chown, false) == result1); | |
88 ASSERT (test_lchown (do_lchown, false) == result2); | |
89 /* We expect 0/0, 0/77, or 77/77, but not 77/0. */ | |
90 ASSERT (result1 <= result2); | |
91 ASSERT (close (dfd) == 0); | |
92 | |
93 /* FIXME - add additional tests of dfd not at current directory. */ | |
94 return result1 | result2; | |
95 } |