blob: fcfd1bdf534440488cfaf0eaed1281b1b142fd46 [file] [log] [blame]
Elliott Hughes15b641a2014-05-14 18:18:55 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Dan Albert98972592014-05-30 16:00:53 -070017#include <errno.h>
Elliott Hughes15b641a2014-05-14 18:18:55 -070018#include <new>
19#include <stdlib.h>
20
Dan Albert98972592014-05-30 16:00:53 -070021#include "private/libc_logging.h"
22
Elliott Hughes15b641a2014-05-14 18:18:55 -070023const std::nothrow_t std::nothrow = {};
24
25void* operator new(std::size_t size) {
26 void* p = malloc(size);
27 if (p == NULL) {
Dan Albert98972592014-05-30 16:00:53 -070028 __libc_fatal("new failed to allocate %zu bytes", size);
Elliott Hughes15b641a2014-05-14 18:18:55 -070029 }
30 return p;
31}
32
33void* operator new[](std::size_t size) {
34 void* p = malloc(size);
35 if (p == NULL) {
Dan Albert98972592014-05-30 16:00:53 -070036 __libc_fatal("new[] failed to allocate %zu bytes", size);
Elliott Hughes15b641a2014-05-14 18:18:55 -070037 }
38 return p;
39}
40
41void operator delete(void* ptr) {
42 free(ptr);
43}
44
45void operator delete[](void* ptr) {
46 free(ptr);
47}
48
49void* operator new(std::size_t size, const std::nothrow_t&) {
50 return malloc(size);
51}
52
53void* operator new[](std::size_t size, const std::nothrow_t&) {
54 return malloc(size);
55}
56
57void operator delete(void* ptr, const std::nothrow_t&) {
58 free(ptr);
59}
60
61void operator delete[](void* ptr, const std::nothrow_t&) {
62 free(ptr);
63}