diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2019-05-05 01:33:26 +0200 | 
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2019-05-05 01:33:26 +0200 | 
| commit | ace14a9b7d713bf5f413abd257829cb6fb1c027b (patch) | |
| tree | b6cf3b843ff52cc2369245f7e4d7dccb21beff94 | |
| parent | 5a76a77a9651dd52560578bb509c917abba1d83c (diff) | |
proto/libevdev: fix error handling code harder
Issue: #944
| -rw-r--r-- | proto-libevdev/ftnoir_protocol_libevdev.cpp | 18 | 
1 files changed, 15 insertions, 3 deletions
| diff --git a/proto-libevdev/ftnoir_protocol_libevdev.cpp b/proto-libevdev/ftnoir_protocol_libevdev.cpp index 27b73f2d..612f5b27 100644 --- a/proto-libevdev/ftnoir_protocol_libevdev.cpp +++ b/proto-libevdev/ftnoir_protocol_libevdev.cpp @@ -1,3 +1,8 @@ +// strerror_r(3) +#ifndef _POSIX_C_SOURCE +#   define _POSIX_C_SOURCE 200112L +#endif +  #include "ftnoir_protocol_libevdev.h"  #include "api/plugin-api.hpp"  #include "compat/math.hpp" @@ -120,10 +125,17 @@ module_status evdev::initialize()  {      if (error_code)      { +        const char* msg;          char buf[128] {}; -        (void)strerror_r(error_code, buf, sizeof(buf)); -        return error(QStringLiteral("libevdev call '%1' failed with error '%2' (%3)") -                     .arg(!error_expr ? "<NULL>" : error_expr, buf).arg(error_code)); + +        if (!(msg = strerror_r(error_code, buf, sizeof(buf)))) +        { +            snprintf(buf, sizeof(buf), "%d", error_code); +            msg = buf; +        } + +        return error(QStringLiteral("libevdev call '%1' failed with error '%2'") +                     .arg(!error_expr ? "<NULL>" : error_expr, msg));      }      else          return {}; | 
