summaryrefslogtreecommitdiff
path: root/src/gmalloc.c
diff options
context:
space:
mode:
authorYAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>2007-08-09 03:07:07 +0000
committerYAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>2007-08-09 03:07:07 +0000
commit72359c326537cd6986b5f6ba9c8833b268d24c93 (patch)
tree46ff4808e54c2ecb96044dae7a4882262f85e3b9 /src/gmalloc.c
parent22ce475b428311f8c7cfb07dbf12103097ab7d02 (diff)
(posix_memalign): New function.
Diffstat (limited to 'src/gmalloc.c')
-rw-r--r--src/gmalloc.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/gmalloc.c b/src/gmalloc.c
index ea6ccc4bf1..ccc08e1ff6 100644
--- a/src/gmalloc.c
+++ b/src/gmalloc.c
@@ -129,6 +129,8 @@ extern FREE_RETURN_TYPE free PP ((__ptr_t __ptr));
#if ! (defined (_MALLOC_INTERNAL) && __DJGPP__ - 0 == 1) /* Avoid conflict. */
extern __ptr_t memalign PP ((__malloc_size_t __alignment,
__malloc_size_t __size));
+extern int posix_memalign PP ((__ptr_t *, __malloc_size_t,
+ __malloc_size_t size));
#endif
/* Allocate SIZE bytes on a page boundary. */
@@ -1857,6 +1859,36 @@ memalign (alignment, size)
return result;
}
+#ifndef ENOMEM
+#define ENOMEM 12
+#endif
+
+#ifndef EINVAL
+#define EINVAL 22
+#endif
+
+int
+posix_memalign (memptr, alignment, size)
+ __ptr_t *memptr;
+ __malloc_size_t alignment;
+ __malloc_size_t size;
+{
+ __ptr_t mem;
+
+ if (alignment == 0
+ || alignment % sizeof (__ptr_t) != 0
+ || (alignment & (alignment - 1)) != 0)
+ return EINVAL;
+
+ mem = memalign (alignment, size);
+ if (mem == NULL)
+ return ENOMEM;
+
+ *memptr = mem;
+
+ return 0;
+}
+
#endif /* Not DJGPP v1 */
/* Allocate memory on a page boundary.
Copyright (C) 1991, 92, 93, 94, 96 Free Software Foundation, Inc.