-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathusb_error.cpp
More file actions
43 lines (32 loc) · 852 Bytes
/
Copy pathusb_error.cpp
File metadata and controls
43 lines (32 loc) · 852 Bytes
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
//
// Java Does USB
// Copyright (c) 2022 Manuel Bleichenbacher
// Licensed under MIT License
// https://opensource.org/licenses/MIT
//
// Reference C++ code for macOS
//
#include "usb_error.hpp"
#include <errno.h>
#include <string.h>
usb_error::usb_error(const char* message, int code) noexcept
: _message(full_message(message, code)), _code(code) { }
usb_error::~usb_error() noexcept { }
const char* usb_error::what() const noexcept {
return _message.c_str();
}
long usb_error::error_code() {
return _code;
}
void usb_error::throw_error(const char* message) {
throw usb_error(message, errno);
}
std::string usb_error::full_message(const char* message, int code) {
if (code == 0)
return message;
std::string msg(message);
msg += " (";
msg += strerror(code);
msg += ")";
return msg;
}