aboutsummaryrefslogtreecommitdiffstats
path: root/aligned_strndup.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2018-11-25 21:42:12 +0100
committerMattias Andrée <maandree@kth.se>2018-11-25 21:42:12 +0100
commit7e34c31e6bd3d4edcdc97a8afbd400af67060295 (patch)
treec109def7a6ef6f1178da52993dd28afeedcee3ec /aligned_strndup.c
parentAdd arraydup macros (diff)
downloadlibsimple-7e34c31e6bd3d4edcdc97a8afbd400af67060295.tar.gz
libsimple-7e34c31e6bd3d4edcdc97a8afbd400af67060295.tar.bz2
libsimple-7e34c31e6bd3d4edcdc97a8afbd400af67060295.tar.xz
Add [e[n]]aligned_str[n]dup and aligned_str[n]dupa
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'aligned_strndup.c')
-rw-r--r--aligned_strndup.c29
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