summaryrefslogtreecommitdiff
path: root/tools/e2fsprogs/patches/005-posix_memalign.patch
blob: 2ce4ead892e7ceb482567ff12f752f5f28621cf0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
--- a/lib/ext2fs/ext2fs.h
+++ b/lib/ext2fs/ext2fs.h
@@ -1212,7 +1212,26 @@
 
 	if (align == 0)
 		align = 8;
-	if (retval = posix_memalign((void **) ptr, align, size)) {
+#ifdef HAVE_POSIX_MEMALIGN
+	retval = posix_memalign((void **)ptr, align, size);
+#else
+#ifdef HAVE_MEMALIGN
+    if ((*(void **)ptr = (void *)memalign(align, size)) == NULL)
+    	retval = errno;
+    else
+    	retval = 0;
+#else
+#ifdef HAVE_VALLOC
+    if ((*(void **)ptr = valloc(size)) == NULL)
+    	retval = errno;
+    else
+    	retval = 0;
+#else
+# error "Impossible to allocate aligned memory!"
+#endif /* HAVE_VALLOC */
+#endif /* HAVE_MEMALIGN */
+#endif /* HAVE_POSIX_MEMALIGN */
+	if (retval) {
 		if (retval == ENOMEM)
 			return EXT2_ET_NO_MEMORY;
 		return retval;
--