root/branches/cu-security-branch/src/common/misc/pint-mem.c @ 8397

Revision 8397, 1.2 KB (checked in by nlmills, 3 years ago)

initial merge with Orange-Branch. much will be broken

Line 
1/*
2 * (C) 2001 Clemson University and The University of Chicago
3 *
4 * See COPYING in top-level directory.
5 */
6
7#define _XOPEN_SOURCE 600
8#include <errno.h>
9#include <stdlib.h>
10#include <string.h>
11#ifdef HAVE_MALLOC_H
12#include <malloc.h>
13#endif
14
15/* prototype definitions */
16inline void* PINT_mem_aligned_alloc(size_t size, size_t alignment);
17inline void PINT_mem_aligned_free(void *ptr);
18
19/* PINT_mem_aligned_alloc()
20 *
21 * allocates a memory region of the specified size and returns a
22 * pointer to the region.  The address of the memory will be evenly
23 * divisible by alignment.
24 *
25 * returns pointer to memory on success, NULL on failure
26 */
27inline void* PINT_mem_aligned_alloc(size_t size, size_t alignment)
28{
29    int ret;
30    void *ptr;
31
32    ret = posix_memalign(&ptr, alignment, size);
33    if(ret != 0)
34    {
35        errno = ret;
36        return NULL;
37    }
38    memset(ptr, 0, size);
39    return ptr;
40}
41
42/* PINT_mem_aligned_free()
43 *
44 * frees memory region previously allocated with
45 * PINT_mem_aligned_alloc()
46 *
47 * no return value
48 */
49inline void PINT_mem_aligned_free(void *ptr)
50{
51    free(ptr);
52    return;
53}
54
55/*
56 * Local variables:
57 *  c-indent-level: 4
58 *  c-basic-offset: 4
59 * End:
60 *
61 * vim: ts=8 sts=4 sw=4 expandtab
62 */
63
64
Note: See TracBrowser for help on using the browser.