diff options
| author | tedu <> | 2010-05-18 22:24:55 +0000 |
|---|---|---|
| committer | tedu <> | 2010-05-18 22:24:55 +0000 |
| commit | 0800e860cf192fde131a6141be73b2e01cedd301 (patch) | |
| tree | a6c0f4a1cf1cb7596fb9279f0a7ff14d13a1317e /src/lib/libc/stdlib/malloc.c | |
| parent | 85b4a90e5749e07fbbe38899c0378ac76f9603fa (diff) | |
| download | openbsd-0800e860cf192fde131a6141be73b2e01cedd301.tar.gz openbsd-0800e860cf192fde131a6141be73b2e01cedd301.tar.bz2 openbsd-0800e860cf192fde131a6141be73b2e01cedd301.zip | |
add posix_madvise, posix_memalign, strndup, and strnlen. mostly from
brad and millert, with hints from guenther, jmc, and otto I think.
ok previous.
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libc/stdlib/malloc.c | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/lib/libc/stdlib/malloc.c b/src/lib/libc/stdlib/malloc.c index 9cee3e5935..902b69c216 100644 --- a/src/lib/libc/stdlib/malloc.c +++ b/src/lib/libc/stdlib/malloc.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: malloc.c,v 1.124 2010/01/13 12:40:11 otto Exp $ */ | 1 | /* $OpenBSD: malloc.c,v 1.125 2010/05/18 22:24:55 tedu Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2008 Otto Moerbeek <otto@drijf.net> | 3 | * Copyright (c) 2008 Otto Moerbeek <otto@drijf.net> |
| 4 | * | 4 | * |
| @@ -1488,3 +1488,28 @@ calloc(size_t nmemb, size_t size) | |||
| 1488 | return r; | 1488 | return r; |
| 1489 | } | 1489 | } |
| 1490 | 1490 | ||
| 1491 | int | ||
| 1492 | posix_memalign(void **memptr, size_t alignment, size_t size) | ||
| 1493 | { | ||
| 1494 | void *result; | ||
| 1495 | |||
| 1496 | /* Make sure that alignment is a large enough power of 2. */ | ||
| 1497 | if (((alignment - 1) & alignment) != 0 || alignment < sizeof(void *) || | ||
| 1498 | alignment > MALLOC_PAGESIZE) | ||
| 1499 | return EINVAL; | ||
| 1500 | |||
| 1501 | /* | ||
| 1502 | * max(size, alignment) is enough to assure the requested alignment, | ||
| 1503 | * since the allocator always allocates power-of-two blocks. | ||
| 1504 | */ | ||
| 1505 | if (size < alignment) | ||
| 1506 | size = alignment; | ||
| 1507 | result = malloc(size); | ||
| 1508 | |||
| 1509 | if (result == NULL) | ||
| 1510 | return ENOMEM; | ||
| 1511 | |||
| 1512 | *memptr = result; | ||
| 1513 | return 0; | ||
| 1514 | } | ||
| 1515 | |||
