]> git.sur5r.net Git - i3/i3/blob - libi3/strndup.c
i3-msg: check reply in quiet mode
[i3/i3] / libi3 / strndup.c
1 /*
2  * vim:ts=4:sw=4:expandtab
3  *
4  * i3 - an improved dynamic tiling window manager
5  * © 2009 Michael Stapelberg and contributors (see also: LICENSE)
6  *
7  */
8 #include "libi3.h"
9
10 #include <sys/types.h>
11 #include <string.h>
12
13 #if defined(__APPLE__)
14
15 /*
16  * Taken from FreeBSD
17  * Returns a pointer to a new string which is a duplicate of the
18  * string, but only copies at most n characters.
19  *
20  */
21 char *strndup(const char *str, size_t n) {
22     size_t len;
23     char *copy;
24
25     for (len = 0; len < n && str[len]; len++)
26         continue;
27
28     copy = smalloc(len + 1);
29     memcpy(copy, str, len);
30     copy[len] = '\0';
31     return (copy);
32 }
33
34 #endif