Add strnlen on platforms that don't have it, such as OS X

This commit is contained in:
Greg Smith
2011-10-20 17:04:29 -05:00
committed by Jaime Casanova
parent cb764b180d
commit 27396f462a
4 changed files with 17 additions and 0 deletions

View File

@@ -33,3 +33,4 @@
1.1.1 2011-XX-XX
Add --ignore-rsync-warning (Cédric)
Add strnlen for compatibility with OS X (Greg)

View File

@@ -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[],

View File

@@ -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)

View File

@@ -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_ */