use memmem and strndup from FreeBSD on Darwin (Thanks Marcus)

This commit is contained in:
Michael Stapelberg 2011-07-17 15:18:45 +02:00
parent fc583adb99
commit 02dfb8e891
2 changed files with 60 additions and 25 deletions

View File

@ -164,4 +164,18 @@ char *get_process_filename(const char *prefix);
*/
void i3_restart(bool forget_layout);
#if defined(__OpenBSD__) || defined(__APPLE__)
/*
* Taken from FreeBSD
* Find the first occurrence of the byte string s in byte string l.
*
*/
void *memmem(const void *l, size_t l_len, const void *s, size_t s_len);
#endif
#if defined(__APPLE__)
#endif
#endif

View File

@ -448,9 +448,7 @@ void i3_restart(bool forget_layout) {
/* not reached */
}
#if 0
#if defined(__OpenBSD__)
#if defined(__OpenBSD__) || defined(__APPLE__)
/*
* Taken from FreeBSD
@ -485,4 +483,27 @@ void *memmem(const void *l, size_t l_len, const void *s, size_t s_len) {
}
#endif
#if defined(__APPLE__)
/*
* Taken from FreeBSD
* Returns a pointer to a new string which is a duplicate of the
* string, but only copies at most n characters.
*
*/
char *strndup(const char *str, size_t n) {
size_t len;
char *copy;
for (len = 0; len < n && str[len]; len++)
continue;
if ((copy = malloc(len + 1)) == NULL)
return (NULL);
memcpy(copy, str, len);
copy[len] = '\0';
return (copy);
}
#endif