blob: c248ed01727d54c05ea0c01c7d03a5f45ed17aa5 [file] [log] [blame]
Andrew Top2a796462018-06-29 09:04:04 -07001// Copyright 2016 The Cobalt Authors. All Rights Reserved.
David Ghandehariace13522016-09-02 22:40:01 -07002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15// A poem (POsix EMulation) for functions in stdio.h
16
17#ifndef STARBOARD_CLIENT_PORTING_POEM_STDIO_POEM_H_
18#define STARBOARD_CLIENT_PORTING_POEM_STDIO_POEM_H_
19
David Ghandehari74e3cb62016-09-15 07:47:48 -070020#if defined(STARBOARD)
21
22#if !defined(POEM_NO_EMULATION)
David Ghandehariace13522016-09-02 22:40:01 -070023
David Ghandehari74e3cb62016-09-15 07:47:48 -070024#include "starboard/memory.h"
David Ghandehari06a3c232016-10-07 13:54:30 -070025#include "starboard/string.h"
David Ghandehariace13522016-09-02 22:40:01 -070026
27#define wcsncmp(s1, s2, c) SbStringCompareWide(s1, s2, c)
28
29// the following functions can have variable number of arguments
30// and, out of compatibility concerns, we chose to not use
31// __VA_ARGS__ functionality.
Andrew Top2a8c8472018-06-13 17:27:01 -070032#undef vsnprintf
David Ghandehariace13522016-09-02 22:40:01 -070033#define vsnprintf SbStringFormat
Andrew Top2a8c8472018-06-13 17:27:01 -070034#undef snprintf
David Ghandehariace13522016-09-02 22:40:01 -070035#define snprintf SbStringFormatF
Andrew Top2a8c8472018-06-13 17:27:01 -070036#undef sprintf
David Ghandehariace13522016-09-02 22:40:01 -070037#define sprintf SbStringFormatUnsafeF
Andrew Top2a8c8472018-06-13 17:27:01 -070038#undef vsscanf
David Ghandehariace13522016-09-02 22:40:01 -070039#define vsscanf SbStringScan
Andrew Top2a8c8472018-06-13 17:27:01 -070040#undef sscanf
David Ghandehariace13522016-09-02 22:40:01 -070041#define sscanf SbStringScanF
Andrew Top2a8c8472018-06-13 17:27:01 -070042#undef malloc
David Ghandehari8c0a79f2016-10-26 10:51:48 -070043#define malloc(sz) SbMemoryAllocate(sz)
Andrew Top2a8c8472018-06-13 17:27:01 -070044#undef calloc
David Ghandehari06a3c232016-10-07 13:54:30 -070045#define calloc(c, s) SbMemoryCalloc(c, s)
Andrew Top2a8c8472018-06-13 17:27:01 -070046#undef free
David Ghandehari8c0a79f2016-10-26 10:51:48 -070047#define free(a) SbMemoryDeallocate(a)
Andrew Top2a8c8472018-06-13 17:27:01 -070048#undef realloc
David Ghandehari8c0a79f2016-10-26 10:51:48 -070049#define realloc(m, sz) SbMemoryReallocate(m, sz)
David Ghandehariace13522016-09-02 22:40:01 -070050
David Ghandehari74e3cb62016-09-15 07:47:48 -070051#endif // POEM_NO_EMULATION
52
53#endif // STARBOARD
David Ghandehariace13522016-09-02 22:40:01 -070054
55#endif // STARBOARD_CLIENT_PORTING_POEM_STDIO_POEM_H_