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

Revision 7941, 1.0 KB (checked in by nlmills, 4 years ago)

merged in changes from summer at LANL

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#ifdef HAVE_MALLOC_H
11#include <malloc.h>
12#endif
13
14#include "pint-mem.h"
15
16/* PINT_mem_aligned_alloc()
17 *
18 * allocates a memory region of the specified size and returns a
19 * pointer to the region.  The address of the memory will be evenly
20 * divisible by alignment.
21 *
22 * returns pointer to memory on success, NULL on failure
23 */
24inline void* PINT_mem_aligned_alloc(size_t size, size_t alignment)
25{
26    int ret;
27    void *ptr;
28
29    ret = posix_memalign(&ptr, alignment, size);
30    if(ret != 0)
31    {
32        errno = ret;
33        return NULL;
34    }
35    return ptr;
36}
37
38/* PINT_mem_aligned_free()
39 *
40 * frees memory region previously allocated with
41 * PINT_mem_aligned_alloc()
42 *
43 * no return value
44 */
45inline void PINT_mem_aligned_free(void *ptr)
46{
47    free(ptr);
48    return;
49}
50
51/*
52 * Local variables:
53 *  c-indent-level: 4
54 *  c-basic-offset: 4
55 * End:
56 *
57 * vim: ts=8 sts=4 sw=4 expandtab
58 */
59
60
Note: See TracBrowser for help on using the browser.