core: implement gpiod_last_strerror()
authorBartosz Golaszewski <bartekgola@gmail.com>
Mon, 9 Jan 2017 11:37:04 +0000 (12:37 +0100)
committerBartosz Golaszewski <bartekgola@gmail.com>
Mon, 9 Jan 2017 11:37:04 +0000 (12:37 +0100)
This is the same as gpiod_strerror() except that it automatically
uses the last error number by calling gpiod_errno().

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
core.c
gpiod.h

diff --git a/core.c b/core.c
index d754e1b34453b19bc0a60a2775e937b754f5511f..de5dff23fc92355980f322e7c28989b73110d134 100644 (file)
--- a/core.c
+++ b/core.c
@@ -130,6 +130,11 @@ const char * gpiod_strerror(int errnum)
                return error_descr[errnum - __GPIOD_ERRNO_OFFSET];
 }
 
+const char * gpiod_last_strerror(void)
+{
+       return gpiod_strerror(gpiod_errno());
+}
+
 int gpiod_simple_get_value(const char *device,
                           unsigned int offset, bool active_low)
 {
diff --git a/gpiod.h b/gpiod.h
index c5752c9f72c8b75dc454b8c598f7ef8d592a4d9b..e75e3d29a483de62e86a4b9dbf0feb187bf8a738 100644 (file)
--- a/gpiod.h
+++ b/gpiod.h
@@ -96,6 +96,12 @@ int gpiod_errno(void) GPIOD_API;
  */
 const char * gpiod_strerror(int errnum) GPIOD_API;
 
+/**
+ * @brief Convert the last libgpiod error number to a human-readable string.
+ * @return Pointer to a null-terminated error description.
+ */
+const char * gpiod_last_strerror(void) GPIOD_API;
+
 /**
  * @}
  *