1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) Linux Test Project, 2006-2021
4 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
5 * Author: William Roske
6 * Ported to LTP: Dave Fenner
7 */
8
9 /*\
10 * [Description]
11 *
12 * Basic test for fchown(). Call fchown() on a fd and expect it to pass.
13 */
14
15 #include <fcntl.h>
16 #include <sys/stat.h>
17 #include <sys/types.h>
18
19 #include "tst_test.h"
20 #include "compat_tst_16.h"
21
22 #define FILENAME "fchown01_testfile"
23 #define MODE 0700
24
25 static int fd;
26 static uid_t uid;
27 static gid_t gid;
28
run(void)29 static void run(void)
30 {
31 TST_EXP_PASS(FCHOWN(fd, uid, gid),
32 "fchown(%i, %i, %i)", fd, uid, gid);
33 }
34
setup(void)35 static void setup(void)
36 {
37 UID16_CHECK(uid = geteuid(), "fchown");
38 GID16_CHECK(gid = getegid(), "fchown");
39 fd = SAFE_OPEN(FILENAME, O_RDWR | O_CREAT, MODE);
40 }
41
cleanup(void)42 static void cleanup(void)
43 {
44 if (fd > 0)
45 SAFE_CLOSE(fd);
46 }
47
48 static struct tst_test test = {
49 .needs_tmpdir = 1,
50 .setup = setup,
51 .cleanup = cleanup,
52 .test_all = run,
53 };
54