]> granicus.if.org Git - strace/blob - tests/fchownat.c
Update copyright headers
[strace] / tests / fchownat.c
1 /*
2  * Check decoding of fchownat syscall.
3  *
4  * Copyright (c) 2016-2018 Dmitry V. Levin <ldv@altlinux.org>
5  * All rights reserved.
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  */
9
10 #include "tests.h"
11 #include <asm/unistd.h>
12 #include <fcntl.h>
13
14 #if defined __NR_fchownat && defined AT_FDCWD && defined AT_SYMLINK_NOFOLLOW
15
16 # include <stdio.h>
17 # include <unistd.h>
18
19 int
20 main(void)
21 {
22         static const char sample[] = "fchownat_sample";
23         uid_t uid = geteuid();
24         uid_t gid = getegid();
25
26         if (open(sample, O_RDONLY | O_CREAT, 0400) == -1)
27                 perror_msg_and_fail("open");
28
29         long rc = syscall(__NR_fchownat, AT_FDCWD, sample, uid, gid, 0);
30         printf("fchownat(AT_FDCWD, \"%s\", %d, %d, 0) = %s\n",
31                sample, uid, gid, sprintrc(rc));
32
33         if (unlink(sample))
34                 perror_msg_and_fail("unlink");
35
36         rc = syscall(__NR_fchownat, AT_FDCWD,
37                      sample, -1, -1L, AT_SYMLINK_NOFOLLOW);
38         printf("fchownat(AT_FDCWD, \"%s\", -1, -1, AT_SYMLINK_NOFOLLOW) = %s\n",
39                sample, sprintrc(rc));
40
41         puts("+++ exited with 0 +++");
42         return 0;
43 }
44
45 #else
46
47 SKIP_MAIN_UNDEFINED("__NR_fchownat && AT_FDCWD && AT_SYMLINK_NOFOLLOW")
48
49 #endif