1// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5#include "platform/globals.h"
6#if defined(HOST_OS_FUCHSIA)
7
8#include <memory>
9
10#include "lib/sys/cpp/component_context.h"
11#include "platform/utils.h"
12#include "platform/utils_fuchsia.h"
13
14namespace dart {
15
16char* Utils::StrNDup(const char* s, intptr_t n) {
17 return strndup(s, n);
18}
19
20char* Utils::StrDup(const char* s) {
21 return strdup(s);
22}
23
24intptr_t Utils::StrNLen(const char* s, intptr_t n) {
25 return strnlen(s, n);
26}
27
28int Utils::SNPrint(char* str, size_t size, const char* format, ...) {
29 va_list args;
30 va_start(args, format);
31 int retval = VSNPrint(str, size, format, args);
32 va_end(args);
33 return retval;
34}
35
36int Utils::VSNPrint(char* str, size_t size, const char* format, va_list args) {
37 int retval = vsnprintf(str, size, format, args);
38 if (retval < 0) {
39 FATAL1("Fatal error in Utils::VSNPrint with format '%s'", format);
40 }
41 return retval;
42}
43
44int Utils::Close(int fildes) {
45 return close(fildes);
46}
47size_t Utils::Read(int filedes, void* buf, size_t nbyte) {
48 return read(filedes, buf, nbyte);
49}
50int Utils::Unlink(const char* path) {
51 return unlink(path);
52}
53
54sys::ComponentContext* ComponentContext() {
55 static std::unique_ptr<sys::ComponentContext> context =
56 sys::ComponentContext::CreateAndServeOutgoingDirectory();
57 return context.get();
58}
59
60} // namespace dart
61
62#endif // defined(HOST_OS_FUCHSIA)
63