summaryrefslogtreecommitdiff
path: root/src/helper/ioctl.cpp
blob: 21a1ccb4d64f1d54827f9a074316d32ce6894f38 (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* SPDX-License-Identifier: MIT */

#include "drm++/helper/ioctl.hpp"

#include <format>
#include <string>

#include <errno.h>

using namespace drm::ioctl;

Exception::Exception(int fd, unsigned long op)
        : m_fd(fd), m_op(op), m_syserrno(errno) {
    switch (errno) {
        case EBADF:
            this->m_code = Error::BadFileDescriptor;
            this->m_what = std::format(
                "ioctl({}, 0x{:x}) failed: Invalid file descriptor",
                this->m_fd, this->m_op
            );
            break;
        case EINVAL:
        case ENOTTY:
            this->m_code = Error::InvalidArgument;
            this->m_what = std::format(
                "ioctl({}, 0x{:x}) failed: Invalid argument (errno {})",
                this->m_fd, this->m_op, this->m_syserrno
            );
            break;
        case ENOTSUP:
            this->m_code = Error::NotSupported;
            this->m_what = std::format(
                "ioctl({}, 0x{:x}) failed: Operation not supported",
                this->m_fd, this->m_op
            );
            break;
        default:
            this->m_code = Error::Other;
            this->m_what = std::format(
                "ioctl({}, 0x{:x}) failed: Unknown error (errno {})",
                this->m_fd, this->m_op, this->m_syserrno
            );
    }
}


Exception::~Exception() = default;