Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : */
9 :
10 : #include <internal/oslmemory.h>
11 :
12 : #include <stdlib.h>
13 : #ifdef __ANDROID__
14 : #include <malloc.h>
15 : #endif
16 :
17 0 : void* osl_aligned_alloc( sal_Size align, sal_Size size )
18 : {
19 0 : if (size == 0)
20 : {
21 0 : return NULL;
22 : }
23 : else
24 : {
25 : #if defined __ANDROID__
26 : return memalign(align, size);
27 : #elif defined MAC_OS_X_VERSION_MAX_ALLOWED && MAC_OS_X_VERSION_MAX_ALLOWED < 1060
28 : void* ptr = malloc(size + (align - 1) + sizeof(void*));
29 : if (!ptr) return NULL;
30 : char* aptr = ((char*)ptr) + sizeof(void*);
31 : aptr += (align - ((size_t)aptr & (align - 1))) & (align - 1);
32 : ((void**)aptr)[-1] = ptr;
33 : return aptr;
34 : #else
35 : void* ptr;
36 0 : int err = posix_memalign(&ptr, align, size);
37 0 : return err ? NULL : ptr;
38 : #endif
39 : }
40 : }
41 :
42 0 : void osl_aligned_free( void* p )
43 : {
44 : #if defined MAC_OS_X_VERSION_MAX_ALLOWED && MAC_OS_X_VERSION_MAX_ALLOWED < 1060
45 : free(((void**)p)[-1]);
46 : #else
47 0 : free(p);
48 : #endif
49 0 : }
50 :
51 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|