File: umode_t.c

package info (click to toggle)
strace 6.13%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 71,488 kB
  • sloc: ansic: 176,497; sh: 9,675; makefile: 4,133; cpp: 885; awk: 353; perl: 267; exp: 62; sed: 9
file content (59 lines) | stat: -rw-r--r-- 1,350 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
 * Check decoding of umode_t type syscall arguments.
 *
 * Copyright (c) 2016 Dmitry V. Levin <ldv@strace.io>
 * Copyright (c) 2016-2024 The strace developers.
 * All rights reserved.
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>

#ifndef TEST_SYSCALL_PREFIX_ARGS
# define TEST_SYSCALL_PREFIX_ARGS
#endif
#ifndef TEST_SYSCALL_PREFIX_STR
# define TEST_SYSCALL_PREFIX_STR ""
#endif

static const char sample[] = ".";

static void
test_syscall(unsigned short mode)
{
	unsigned long lmode = (unsigned long) 0xffffffffffff0000ULL | mode;
	long rc = syscall(TEST_SYSCALL_NR, TEST_SYSCALL_PREFIX_ARGS
			  sample, lmode);

	if (mode <= 07)
		printf("%s(%s\"%s\", 00%d) = %s\n",
		       TEST_SYSCALL_STR, TEST_SYSCALL_PREFIX_STR,
		       sample, (int) mode, sprintrc(rc));
	else
		printf("%s(%s\"%s\", %#03ho) = %s\n",
		       TEST_SYSCALL_STR, TEST_SYSCALL_PREFIX_STR,
		       sample, mode, sprintrc(rc));
}

int
main(void)
{
	test_syscall(0);
	test_syscall(0xffff);
	test_syscall(06);
	test_syscall(060);
	test_syscall(0600);
	test_syscall(024);
	test_syscall(S_IFREG);
	test_syscall(S_IFDIR | 06);
	test_syscall(S_IFLNK | 060);
	test_syscall(S_IFIFO | 0600);
	test_syscall(S_IFCHR | 024);
	test_syscall((0xffff & ~S_IFMT) | S_IFBLK);

	puts("+++ exited with 0 +++");
	return 0;
}