Commit b99ed996 authored by Michael Lee's avatar Michael Lee Committed by Facebook Github Bot 0

Android does not always provide posix_memalign

Summary: We could provide `posix_memalign` instead as part of portability, but I am not sure how to tell whether or not it will be available.

Reviewed By: yfeldblum

Differential Revision: D2991432

fb-gh-sync-id: 587314d43779f3b8fead2c41ed05016e6350f2ee
shipit-source-id: 587314d43779f3b8fead2c41ed05016e6350f2ee
parent ab442ee8
......@@ -268,6 +268,7 @@ nobase_follyinclude_HEADERS = \
portability/Constexpr.h \
portability/Environment.h \
portability/GFlags.h \
portability/Stdlib.h \
portability/Syscall.h \
portability/SysTime.h \
portability/SysUio.h \
......@@ -397,6 +398,7 @@ libfolly_la_SOURCES = \
MacAddress.cpp \
MemoryMapping.cpp \
portability/Environment.cpp \
portability/Stdlib.cpp \
portability/SysTime.cpp \
portability/Time.cpp \
Random.cpp \
......
/*
* Copyright 2016 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <folly/portability/Stdlib.h>
#include <errno.h>
#if defined(__ANDROID__)
#include <android/api-level.h>
#if (__ANDROID_API__ <= 15)
int posix_memalign(void** memptr, size_t alignment, size_t size) {
int rc = 0;
int saved_errno = errno;
void* ptr = nullptr;
ptr = memalign(alignment, size);
if (nullptr == ptr) {
rc = errno;
} else {
*memptr = ptr;
}
errno = saved_errno;
return rc;
}
#endif
#endif
/*
* Copyright 2016 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <cstdlib>
extern int posix_memalign(void** memptr, size_t alignment, size_t size);
......@@ -19,9 +19,10 @@
#include <folly/Range.h>
#include <folly/portability/Stdlib.h>
#include <sys/mman.h>
#include <array>
#include <cstdlib>
#include <iterator>
#include <limits>
#include <random>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment