summaryrefslogtreecommitdiff
path: root/NK_C_API.cc
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2018-06-20 12:03:28 +0200
committerSzczepan Zalega <szczepan@nitrokey.com>2018-06-20 12:03:28 +0200
commitf0f1691bc741da48bc2e1adfa4535026ae42d6d3 (patch)
treebca302e1843cffda095223ddc3506a1c7ad94d2c /NK_C_API.cc
parent6e44c2b11bd1be9e080f1179283c49f9bb8955a5 (diff)
downloadlibnitrokey-f0f1691bc741da48bc2e1adfa4535026ae42d6d3.tar.gz
libnitrokey-f0f1691bc741da48bc2e1adfa4535026ae42d6d3.tar.bz2
Replace *out function parameter with return value
Using return value instead of memory manipulation seem to be cleaner solution and less error prone due to avoiding pointer usage. Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'NK_C_API.cc')
-rw-r--r--NK_C_API.cc19
1 files changed, 7 insertions, 12 deletions
diff --git a/NK_C_API.cc b/NK_C_API.cc
index 56340ac..d8b8168 100644
--- a/NK_C_API.cc
+++ b/NK_C_API.cc
@@ -238,28 +238,23 @@ extern "C" {
}
- NK_C_API bool NK_get_device_model(enum NK_device_model *out) {
- if (out == nullptr) {
- return false;
- }
+ NK_C_API enum NK_device_model NK_get_device_model() {
auto m = NitrokeyManager::instance();
try {
auto model = m->get_connected_device_model();
switch (model) {
case DeviceModel::PRO:
- *out = NK_PRO;
- return true;
+ return NK_PRO;
case DeviceModel::STORAGE:
- *out = NK_STORAGE;
- return true;
+ return NK_STORAGE;
default:
- /* unknown device -- should not happen */
- return false;
+ /* unknown or not connected device */
+ return NK_device_model::NK_DISCONNECTED;
}
} catch (const DeviceNotConnected& e) {
- return false;
+ return NK_device_model::NK_DISCONNECTED;
}
- }
+}
void clear_string(std::string &s) {