[rtems commit] libdl: Clear error between dlerror invocations

Chris Johns chrisj at rtems.org
Thu Feb 8 22:32:33 UTC 2018


Module:    rtems
Branch:    4.11
Commit:    a2a9751823d506ccd9cd4264fd2e97032d306cb5
Changeset: http://git.rtems.org/rtems/commit/?id=a2a9751823d506ccd9cd4264fd2e97032d306cb5

Author:    Patrick Gauvin <gauvin at hcs.ufl.edu>
Date:      Sun Jun 26 12:43:25 2016 -0400

libdl: Clear error between dlerror invocations

Updates #2747

---

 cpukit/libdl/dlfcn.c     |  2 ++
 cpukit/libdl/rtl-error.c | 12 ++++++++++++
 cpukit/libdl/rtl-error.h |  5 +++++
 3 files changed, 19 insertions(+)

diff --git a/cpukit/libdl/dlfcn.c b/cpukit/libdl/dlfcn.c
index 3b31bb2..4277caf 100644
--- a/cpukit/libdl/dlfcn.c
+++ b/cpukit/libdl/dlfcn.c
@@ -18,6 +18,7 @@
 #include <stdint.h>
 #include <dlfcn.h>
 #include <rtems/rtl/rtl.h>
+#include "rtl-error.h"
 
 static rtems_rtl_obj_t*
 dl_get_obj_from_handle (void* handle)
@@ -130,6 +131,7 @@ dlerror (void)
 {
   static char msg[64];
   rtems_rtl_get_error (msg, sizeof (msg));
+  rtems_rtl_clear_error ();
   return msg;
 }
 
diff --git a/cpukit/libdl/rtl-error.c b/cpukit/libdl/rtl-error.c
index 5ec4b26..a60074f 100644
--- a/cpukit/libdl/rtl-error.c
+++ b/cpukit/libdl/rtl-error.c
@@ -52,3 +52,15 @@ rtems_rtl_get_error (char* message, size_t max_message)
 
   return EIO;
 }
+
+void
+rtems_rtl_clear_error (void)
+{
+  rtems_rtl_data_t* rtl = rtems_rtl_lock ();
+  if (rtl != NULL)
+  {
+    rtl->last_errno = 0;
+    rtl->last_error[0] = '\0';
+    rtems_rtl_unlock ();
+  }
+}
diff --git a/cpukit/libdl/rtl-error.h b/cpukit/libdl/rtl-error.h
index 0badf51..f1cf4ea 100644
--- a/cpukit/libdl/rtl-error.h
+++ b/cpukit/libdl/rtl-error.h
@@ -37,6 +37,11 @@ extern "C" {
  */
 void rtems_rtl_set_error (int error, const char* format, ...) RTEMS_RTL_PRINTF_ATTR;
 
+/**
+ * Clears the error.
+ */
+void rtems_rtl_clear_error (void);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */



More information about the vc mailing list