2011-01-03 14:00:53 +00:00
|
|
|
// Wrapper for string.h on Mac and MinGW
|
2010-09-07 08:40:00 +00:00
|
|
|
#ifndef _STRING_WRAPPER_H
|
|
|
|
#define _STRING_WRAPPER_H
|
|
|
|
|
2012-03-02 10:10:11 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
#include <Availability.h>
|
|
|
|
#endif
|
|
|
|
|
2010-09-07 08:40:00 +00:00
|
|
|
#include <string.h>
|
2012-03-02 10:10:11 +00:00
|
|
|
#if (defined(__APPLE__) && __MAC_OS_X_VERSION_MIN_REQUIRED < 1070) || defined(__MINGW32__)
|
2010-09-07 08:40:00 +00:00
|
|
|
// need our own implementation of strnlen
|
2012-03-02 10:10:11 +00:00
|
|
|
#ifdef __MINGW32__
|
2010-09-07 08:40:00 +00:00
|
|
|
static size_t strnlen(const char *s, size_t n)
|
|
|
|
{
|
2012-03-02 10:10:11 +00:00
|
|
|
const char *p = (const char *)memchr(s, 0, n);
|
|
|
|
return(p ? p-s : n);
|
|
|
|
}
|
|
|
|
#elif (defined(__APPLE__) && __MAC_OS_X_VERSION_MIN_REQUIRED < 1070)
|
|
|
|
static size_t mw_strnlen(const char *s, size_t n)
|
|
|
|
{
|
|
|
|
if (strnlen != NULL) {
|
|
|
|
return strnlen(s, n);
|
|
|
|
}
|
2012-03-02 10:18:10 +00:00
|
|
|
else {
|
|
|
|
const char *p = (const char *)memchr(s, 0, n);
|
|
|
|
return(p ? p-s : n);
|
|
|
|
}
|
2010-09-07 08:40:00 +00:00
|
|
|
}
|
2012-03-02 10:10:11 +00:00
|
|
|
#define strnlen mw_strnlen
|
2010-09-07 08:40:00 +00:00
|
|
|
#endif
|
2012-03-02 10:10:11 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2010-09-07 08:40:00 +00:00
|
|
|
#endif
|