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