]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Alloc: Use posix_memalign() instead of aligned_alloc()
authorOndrej Zajicek (work) <santiago@crfreenet.org>
Tue, 8 Feb 2022 21:42:00 +0000 (22:42 +0100)
committerOndrej Zajicek (work) <santiago@crfreenet.org>
Tue, 8 Feb 2022 21:42:00 +0000 (22:42 +0100)
For compatibility with older systems use posix_memalign(). We can
switch to aligned_alloc() when we commit to C11 for multithreading.

sysdep/unix/alloc.c

index 5dd70c990c923f3f46eeb3dd41a5457dc9f4d622..0e944d57f3b35039aba344c7062629423c553e5b 100644 (file)
@@ -72,16 +72,17 @@ alloc_page(void)
   {
     void *ret = mmap(NULL, get_page_size(), PROT_WRITE | PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
     if (ret == MAP_FAILED)
-      bug("mmap(%lu) failed: %m", page_size);
+      bug("mmap(%lu) failed: %m", (long unsigned int) page_size);
     return ret;
   }
   else
 #endif
   {
-    void *ret = aligned_alloc(page_size, page_size);
-    if (!ret)
-      bug("aligned_alloc(%lu) failed", page_size);
-    return ret;
+    void *ptr = NULL;
+    int err = posix_memalign(&ptr, page_size, page_size);
+    if (err || !ptr)
+      bug("posix_memalign(%lu) failed", (long unsigned int) page_size);
+    return ptr;
   }
 }