From f0e609bcd48134406fdab4f3ede66da3fd11b09b Mon Sep 17 00:00:00 2001 From: Greg Smith Date: Thu, 20 Oct 2011 17:04:29 -0500 Subject: [PATCH] Add strnlen on platforms that don't have it, such as OS X --- HISTORY | 5 +++-- dbutils.h | 2 ++ strutil.c | 9 +++++++++ strutil.h | 5 +++++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/HISTORY b/HISTORY index bb6ddadc..9a7f0281 100644 --- a/HISTORY +++ b/HISTORY @@ -31,5 +31,6 @@ 1.1.0 2011-03-09 Make options -U, -R and -p not mandatory (Jaime) -X.X.X 2011-XX-XX - Add --ignore-rsync-warning (Cédric) +1.1.1 2011-XX-XX + Add --ignore-rsync-warning (Cédric) + Add strnlen for compatibility with OS X (Greg) diff --git a/dbutils.h b/dbutils.h index 9b41f2c7..c09a8658 100644 --- a/dbutils.h +++ b/dbutils.h @@ -20,6 +20,8 @@ #ifndef _REPMGR_DBUTILS_H_ #define _REPMGR_DBUTILS_H_ +#include "strutil.h" + PGconn *establishDBConnection(const char *conninfo, const bool exit_on_error); PGconn *establishDBConnectionByParams(const char *keywords[], const char *values[], diff --git a/strutil.c b/strutil.c index 6af395e6..0fa3bb0d 100644 --- a/strutil.c +++ b/strutil.c @@ -27,6 +27,15 @@ static int xvsnprintf(char *str, size_t size, const char *format, va_list ap); +/* Add strnlen on platforms that don't have it, like OS X */ +#ifndef strnlen +size_t +strnlen(const char *s, size_t n) +{ + const char *end = (const char *) memchr(s, '\0', n); + return(end ? end - s : n); +} +#endif static int xvsnprintf(char *str, size_t size, const char *format, va_list ap) diff --git a/strutil.h b/strutil.h index ec39cbf4..77babf8b 100644 --- a/strutil.h +++ b/strutil.h @@ -35,4 +35,9 @@ extern int xsnprintf(char *str, size_t size, const char *format, ...); extern int sqlquery_snprintf(char *str, const char *format, ...); extern int maxlen_snprintf(char *str, const char *format, ...); +/* Add strnlen on platforms that don't have it, like OS X */ +#ifndef strnlen +extern size_t strnlen(const char *s, size_t n); +#endif + #endif /* _STRUTIL_H_ */