summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/kapi/kapi_test_util.h
blob: a09871207bfc6603091960e99ebfc11a97055618 (plain) (blame)
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
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Copyright (C) 2026 Sasha Levin <sashal@kernel.org>
 *
 * Compatibility helpers for KAPI selftests.
 *
 * __NR_open does not exist on architectures using the generic syscall table
 * (e.g. arm64, riscv); only __NR_openat does. There the wrapper falls back to
 * openat(AT_FDCWD, ...), which does not go through sys_open, so the sys_open
 * KAPI checks are not exercised.
 */
#ifndef KAPI_TEST_UTIL_H
#define KAPI_TEST_UTIL_H

#include <fcntl.h>
#include <unistd.h>
#include <sys/syscall.h>

#ifndef __NR_open
static inline long kapi_sys_open(const char *pathname, int flags, int mode)
{
	return syscall(__NR_openat, AT_FDCWD, pathname, flags, mode);
}
#else
static inline long kapi_sys_open(const char *pathname, int flags, int mode)
{
	return syscall(__NR_open, pathname, flags, mode);
}
#endif

#endif /* KAPI_TEST_UTIL_H */