~mingw-w64/mingw-w64/experimental

« back to all changes in this revision

Viewing changes to libw64crt/memory/aligned_offset_malloc.c

  • Committer: ktietz70
  • Date: 2009-12-07 19:49:25 UTC
  • Revision ID: svn-v4:4407c894-4637-0410-b4f5-ada5f102cad1:experimental:1611
Rename to iCrt (ironCrate)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <w64crt.h>
2
 
#include "aligned.h"
3
 
 
4
 
void *
5
 
__w64crt_aligned_offset_malloc (size_t sz, size_t align, size_t off)
6
 
{
7
 
  void *ret, *tmp;
8
 
 
9
 
  if ((align & (align - 1)) != 0 || off >= sz)
10
 
    {
11
 
      __w64crt_set_errno (EINVAL);
12
 
      return NULL;
13
 
    }
14
 
 
15
 
  if (align < sizeof(void *))
16
 
    align = sizeof(void *);
17
 
 
18
 
  if ((tmp = __w64crt_malloc (sz + align + sizeof(void *))) == NULL)
19
 
    return NULL;
20
 
 
21
 
  ret = ALIGN_PTR (tmp, align, off);
22
 
  *((void **) SAVED_PTR (ret)) = tmp;
23
 
 
24
 
  return ret;
25
 
}