[tracker] Add strnlen() compat function



commit 94aa24306a0503f32b13994087f2e2777464bddc
Author: Ralph Boehme <sloowfranklin gmail com>
Date:   Sat Nov 2 12:09:41 2013 +0100

    Add strnlen() compat function

 configure.ac                                      |    2 +-
 src/libtracker-common/tracker-os-dependant-unix.c |    9 +++++++++
 src/libtracker-common/tracker-os-dependant.h      |    4 ++++
 3 files changed, 14 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 090ebd2..b713a8d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -133,7 +133,7 @@ AC_CHECK_DECLS(posix_fadvise, [], [], [
 
 # Checks for functions
 AC_CHECK_FUNCS([posix_fadvise])
-AC_CHECK_FUNCS([getline])
+AC_CHECK_FUNCS([getline strnlen])
 
 CFLAGS="$CFLAGS"
 
diff --git a/src/libtracker-common/tracker-os-dependant-unix.c 
b/src/libtracker-common/tracker-os-dependant-unix.c
index 24108f4..4aa99f6 100644
--- a/src/libtracker-common/tracker-os-dependant-unix.c
+++ b/src/libtracker-common/tracker-os-dependant-unix.c
@@ -349,3 +349,12 @@ tracker_memory_setrlimits (void)
 
        return TRUE;
 }
+
+#ifndef HAVE_STRNLEN
+size_t
+strnlen (const char *str, size_t max)
+{
+       const char *end = memchr (str, 0, max);
+       return end ? (size_t)(end - str) : max;
+}
+#endif /* HAVE_STRNLEN */
diff --git a/src/libtracker-common/tracker-os-dependant.h b/src/libtracker-common/tracker-os-dependant.h
index e92ea45..087cba0 100644
--- a/src/libtracker-common/tracker-os-dependant.h
+++ b/src/libtracker-common/tracker-os-dependant.h
@@ -50,6 +50,10 @@ gchar *  tracker_create_permission_string  (struct stat   finfo);
 /* Memory limits */
 gboolean tracker_memory_setrlimits (void);
 
+/* Compatibility functions */
+#ifndef HAVE_STRNLEN
+size_t strnlen (const char *str, size_t max);
+#endif
 G_END_DECLS
 
 #endif /* __LIBTRACKER_COMMON_OS_DEPENDANT_H__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]