diff options
Diffstat (limited to 'aligned_strndup.c')
-rw-r--r-- | aligned_strndup.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/aligned_strndup.c b/aligned_strndup.c new file mode 100644 index 0000000..a714387 --- /dev/null +++ b/aligned_strndup.c @@ -0,0 +1,29 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +char * +libsimple_aligned_strndup(const char *s, size_t alignment, size_t n) /* TODO test */ +{ + char *ret; + n = strnlen(s, n); + ret = aligned_alloc(alignment, (n + 1) + (alignment - (n + 1) % alignment) % alignment); + if (!ret) + return NULL; + memcpy(ret, s, n); + ret[n] = '\0'; + return ret; +} + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif |