v4l2-tracer: check for strerrorname_np()
Commit Message
The v4l2-tracer converts the errno integer to a string using
strerrorname_np(). Check if this function is available and,
if not, use strerror() instead.
Signed-off-by: Deborah Brouwer <deborah.brouwer@collabora.com>
---
configure.ac | 2 ++
utils/v4l2-tracer/libv4l2tracer.cpp | 6 +++---
utils/v4l2-tracer/trace.cpp | 2 +-
utils/v4l2-tracer/v4l2-tracer-common.h | 6 ++++++
4 files changed, 12 insertions(+), 4 deletions(-)
@@ -323,6 +323,8 @@ if test "x$jsonc_pkgconfig" = "xno"; then
AC_MSG_WARN(json-c $JSONC_VERSION_REQUIRED or higher required for v4l2-tracer)
fi
+AC_CHECK_FUNCS([strerrorname_np], AC_DEFINE([HAVE_STRERRORNAME_NP],[1],[glibc has function strerrorname_np]))
+
# Check for pthread
AS_IF([test x$enable_shared != xno],
@@ -201,7 +201,7 @@ int munmap(void *start, size_t length)
json_object *munmap_obj = json_object_new_object();
if (errno)
- json_object_object_add(munmap_obj, "errno", json_object_new_string(strerrorname_np(errno)));
+ json_object_object_add(munmap_obj, "errno", json_object_new_string(STRERR(errno)));
json_object *munmap_args = json_object_new_object();
json_object_object_add(munmap_args, "start", json_object_new_int64((int64_t)start));
@@ -242,7 +242,7 @@ int ioctl(int fd, unsigned long cmd, ...)
int ret = (*original_ioctl)(fd, cmd, arg);
if (errno)
json_object_object_add(ioctl_obj, "errno",
- json_object_new_string(strerrorname_np(errno)));
+ json_object_new_string(STRERR(errno)));
write_json_object_to_json_file(ioctl_obj);
json_object_put(ioctl_obj);
return ret;
@@ -270,7 +270,7 @@ int ioctl(int fd, unsigned long cmd, ...)
int ret = (*original_ioctl)(fd, cmd, arg);
if (errno)
- json_object_object_add(ioctl_obj, "errno", json_object_new_string(strerrorname_np(errno)));
+ json_object_object_add(ioctl_obj, "errno", json_object_new_string(STRERR(errno)));
/* Trace driver arguments if userspace will be reading them i.e. _IOR or _IOWR ioctls */
if ((cmd & IOC_OUT) != 0U) {
@@ -71,7 +71,7 @@ void trace_mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t o
json_object *mmap_obj = json_object_new_object();
if (errno)
- json_object_object_add(mmap_obj, "errno", json_object_new_string(strerrorname_np(errno)));
+ json_object_object_add(mmap_obj, "errno", json_object_new_string(STRERR(errno)));
json_object *mmap_args = json_object_new_object();
json_object_object_add(mmap_args, "addr", json_object_new_int64((int64_t)addr));
@@ -34,6 +34,12 @@
#define STR(x) #x
#define STRING(x) STR(x)
+#ifdef HAVE_STRERRORNAME_NP
+#define STRERR(x) strerrorname_np(x)
+#else
+#define STRERR(x) strerror(x)
+#endif
+
struct val_def {
long val;
const char *str;