You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gn...@apache.org on 2020/06/01 13:11:02 UTC
[incubator-nuttx] 02/03: lib/stdlib: Implement aligned_alloc and
posix_memalign
This is an automated email from the ASF dual-hosted git repository.
gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit b8b61dc070c17585ada10f88986b1192d097872a
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Mon Jun 1 14:21:15 2020 +0800
lib/stdlib: Implement aligned_alloc and posix_memalign
https://linux.die.net/man/3/aligned_alloc
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
Change-Id: I73db1c982e2c3eb73e5960e91c0d471ab967be51
---
include/stdlib.h | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/include/stdlib.h b/include/stdlib.h
index 388cb85..b49723e 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -29,6 +29,7 @@
#include <nuttx/compiler.h>
#include <sys/types.h>
+#include <errno.h>
#include <stdint.h>
#include <limits.h>
@@ -255,6 +256,21 @@ FAR void *memalign(size_t, size_t);
FAR void *zalloc(size_t);
FAR void *calloc(size_t, size_t);
+#ifdef __cplusplus
+inline FAR void *aligned_alloc(size_t a, size_t s)
+{
+ return memalign(a, s);
+}
+
+inline int posix_memalign(FAR void **m, size_t a, size_t s)
+{
+ return (*m = memalign(a, s)) ? OK : ENOMEM;
+}
+#else
+#define aligned_alloc(a, s) memalign((a), (s))
+#define posix_memalign(m, a, s) ((*(m) = memalign((a), (s))) ? OK : ENOMEM)
+#endif
+
struct mallinfo mallinfo(void);
/* Pseudo-Terminals */