1// Copyright 2020 the V8 project authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef V8_BASE_PLATFORM_WRAPPERS_H_ 6#define V8_BASE_PLATFORM_WRAPPERS_H_ 7 8#include <stddef.h> 9#include <stdio.h> 10#include <stdlib.h> 11#include <string.h> 12 13#include "src/base/base-export.h" 14 15#if defined(V8_OS_STARBOARD) 16#include "starboard/memory.h" 17#include "starboard/string.h" 18#endif 19 20namespace v8 { 21namespace base { 22 23#if !defined(V8_OS_STARBOARD) 24 25// Common libstd implementations. 26// inline implementations are preferred here due to performance concerns. 27inline void* Malloc(size_t size) { return malloc(size); } 28 29inline void* Realloc(void* memory, size_t size) { 30 return realloc(memory, size); 31} 32 33inline void Free(void* memory) { return free(memory); } 34 35inline void* Calloc(size_t count, size_t size) { return calloc(count, size); } 36 37inline char* Strdup(const char* source) { return strdup(source); } 38 39inline FILE* Fopen(const char* filename, const char* mode) { 40 return fopen(filename, mode); 41} 42 43inline int Fclose(FILE* stream) { return fclose(stream); } 44 45#else // V8_OS_STARBOARD 46 47inline void* Malloc(size_t size) { return SbMemoryAllocate(size); } 48 49inline void* Realloc(void* memory, size_t size) { 50 return SbMemoryReallocate(memory, size); 51} 52 53inline void Free(void* memory) { return SbMemoryDeallocate(memory); } 54 55inline void* Calloc(size_t count, size_t size) { 56 return SbMemoryCalloc(count, size); 57} 58 59inline char* Strdup(const char* source) { return SbStringDuplicate(source); } 60 61inline FILE* Fopen(const char* filename, const char* mode) { return NULL; } 62 63inline int Fclose(FILE* stream) { return -1; } 64 65#endif // V8_OS_STARBOARD 66 67} // namespace base 68} // namespace v8 69 70#endif // V8_BASE_PLATFORM_WRAPPERS_H_ 71