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