[haiku-commits] Change in haiku[master]: C11: add aligned_alloc()

  • From: Gerrit <review@xxxxxxxxxxxxxxxxxxx>
  • To: waddlesplash <waddlesplash@xxxxxxxxx>, haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 31 Oct 2020 19:50:53 +0000

From Jérôme Duval <jerome.duval@xxxxxxxxx>:

Jérôme Duval has uploaded this change for review. ( 
https://review.haiku-os.org/c/haiku/+/3377 ;)


Change subject: C11: add aligned_alloc()
......................................................................

C11: add aligned_alloc()
---
M headers/compatibility/bsd/features.h
M headers/posix/stdlib.h
M src/system/libroot/posix/malloc_hoard2/wrapper.cpp
3 files changed, 19 insertions(+), 0 deletions(-)



  git pull ssh://git.haiku-os.org:22/haiku refs/changes/77/3377/1

diff --git a/headers/compatibility/bsd/features.h 
b/headers/compatibility/bsd/features.h
index 4513b50..1450c56 100644
--- a/headers/compatibility/bsd/features.h
+++ b/headers/compatibility/bsd/features.h
@@ -12,4 +12,9 @@
 #endif


+#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
+       #define _ISOC11_SOURCE
+#endif
+
+
 #endif // _FEATURES_H
diff --git a/headers/posix/stdlib.h b/headers/posix/stdlib.h
index 4890caf..ebaa9ec 100644
--- a/headers/posix/stdlib.h
+++ b/headers/posix/stdlib.h
@@ -49,6 +49,9 @@
 extern void            free(void *pointer);
 extern void            *malloc(size_t size);
 extern int             posix_memalign(void **_pointer, size_t alignment, 
size_t size);
+#ifdef _ISOC11_SOURCE
+extern void    *aligned_alloc(size_t alignment, size_t size);
+#endif
 extern void            *realloc(void *oldPointer, size_t newSize);

 /* process termination */
diff --git a/src/system/libroot/posix/malloc_hoard2/wrapper.cpp 
b/src/system/libroot/posix/malloc_hoard2/wrapper.cpp
index b1ce800..c5e8c43 100644
--- a/src/system/libroot/posix/malloc_hoard2/wrapper.cpp
+++ b/src/system/libroot/posix/malloc_hoard2/wrapper.cpp
@@ -443,6 +443,17 @@
 }


+extern "C" void *
+aligned_alloc(size_t alignment, size_t size)
+{
+       if (size % alignment != 0) {
+               __set_errno(B_BAD_VALUE);
+               return NULL;
+       }
+       return memalign(alignment, size);
+}
+
+
 extern "C" int
 posix_memalign(void **_pointer, size_t alignment, size_t size)
 {

--
To view, visit https://review.haiku-os.org/c/haiku/+/3377
To unsubscribe, or for help writing mail filters, visit 
https://review.haiku-os.org/settings

Gerrit-Project: haiku
Gerrit-Branch: master
Gerrit-Change-Id: If648c0e27ed946874d393e8e33a4548b70c8ecdb
Gerrit-Change-Number: 3377
Gerrit-PatchSet: 1
Gerrit-Owner: Jérôme Duval <jerome.duval@xxxxxxxxx>
Gerrit-MessageType: newchange

Other related posts:

  • » [haiku-commits] Change in haiku[master]: C11: add aligned_alloc() - Gerrit