| 20 | #ifdef __APPLE__ |
| 21 | #ifndef __MAC_OS_X_VERSION_MIN_REQUIRED |
| 22 | #if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050 |
| 23 | #include <Availability.h> |
| 24 | #else |
| 25 | #include <AvailabilityMacros.h> |
| 26 | #endif |
| 27 | #endif |
| 28 | #if __MAC_OS_X_VERSION_MIN_REQUIRED <= 1060 |
| 29 | #define strndup osx_strndup |
| 30 | #define strnlen osx_strnlen |
| 31 | |
| 32 | static size_t |
| 33 | osx_strnlen (const char *string, size_t maxlen) |
| 34 | { |
| 35 | const char *end = memchr (string, '\0', maxlen); |
| 36 | return end ? (size_t) (end - string) : maxlen; |
| 37 | } |
| 38 | |
| 39 | static char * |
| 40 | osx_strndup (char const *s, size_t n) |
| 41 | { |
| 42 | size_t len = strnlen (s, n); |
| 43 | char *new = malloc (len + 1); |
| 44 | |
| 45 | if (new == NULL) |
| 46 | return NULL; |
| 47 | |
| 48 | new[len] = '\0'; |
| 49 | return memcpy (new, s, len); |
| 50 | } |
| 51 | #endif |
| 52 | #endif |
| 53 | |