1
0
mirror of https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git synced 2026-10-24 00:48:53 +03:00
Files
libgpiod/bindings/cxx/tests/check-kernel.cpp
Bartosz Golaszewski b7ba732e6a treewide: libgpiod v2 implementation
This commit is the result of a squash of all the commits created during
the development of libgpiod v2. This is done to preserve bisectability
of the git tree. It contains significant re-writes of the core C library
as well as C++ and python bindings. The tools have been adjusted to work
with the new API but have not undergone significant changes yet.

This commit contains the bulk of the work on libgpiod v2 but the
development continues with more changes planned.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
[Ben: fix format specifier for uint64_t]
Signed-off-by: Ben Hutchings <ben.hutchings@mind.be>
[Viresh: Fix ioctl number for gpiod_line_request_reconfigure_lines()]
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
[Kent: bug fixes, improvements, better pointer contracts, type strictness]
Signed-off-by: Kent Gibson <warthog618@gmail.com>
2022-10-31 11:15:14 +01:00

49 lines
1.3 KiB
C++

// SPDX-License-Identifier: GPL-2.0-or-later
// SPDX-FileCopyrightText: 2017-2022 Bartosz Golaszewski <brgl@bgdev.pl>
#include <linux/version.h>
#include <sys/utsname.h>
#include <system_error>
#include <sstream>
namespace {
class kernel_checker
{
public:
kernel_checker(int major, int minor, int release)
{
int curr_major, curr_minor, curr_release, curr_ver, req_ver;
::std::string major_str, minor_str, release_str;
::utsname un;
int ret;
ret = ::uname(::std::addressof(un));
if (ret)
throw ::std::system_error(errno, ::std::system_category(),
"unable to read the kernel version");
::std::stringstream ver_stream(::std::string(un.release));
::std::getline(ver_stream, major_str, '.');
::std::getline(ver_stream, minor_str, '.');
::std::getline(ver_stream, release_str, '-');
curr_major = ::std::stoi(major_str, nullptr, 0);
curr_minor = ::std::stoi(minor_str, nullptr, 0);
curr_release = ::std::stoi(release_str, nullptr, 0);
curr_ver = KERNEL_VERSION(curr_major, curr_minor, curr_release);
req_ver = KERNEL_VERSION(major, minor, release);
if (curr_ver < req_ver)
throw ::std::runtime_error("kernel release must be at least: " +
::std::to_string(major) + "." +
::std::to_string(minor) + "." +
::std::to_string(release));
}
};
kernel_checker require_kernel(5, 19, 0);
} /* namespace */