| 743 | #ifdef __APPLE__ |
| 744 | #include <Availability.h> |
| 745 | #if __MAC_OS_X_VERSION_MIN_REQUIRED <= 1060 |
| 746 | static char * strndup (char const *s, size_t n); |
| 747 | static size_t strnlen (const char *string, size_t maxlen); |
| 748 | |
| 749 | static size_t |
| 750 | strnlen (const char *string, size_t maxlen) |
| 751 | { |
| 752 | const char *end = memchr (string, '\0', maxlen); |
| 753 | return end ? (size_t) (end - string) : maxlen; |
| 754 | } |
| 755 | |
| 756 | static char * |
| 757 | strndup (char const *s, size_t n) |
| 758 | { |
| 759 | size_t len = strnlen (s, n); |
| 760 | char *new = malloc (len + 1); |
| 761 | |
| 762 | if (new == NULL) |
| 763 | return NULL; |
| 764 | |
| 765 | new[len] = '\0'; |
| 766 | return memcpy (new, s, len); |
| 767 | } |
| 768 | #endif |
| 769 | #endif |