Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
utils_fuchsia.cc
Go to the documentation of this file.
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(DART_HOST_OS_FUCHSIA)
7
8#include <memory>
9#include <utility>
10
11#include "lib/async/default.h"
12#include "lib/inspect/component/cpp/component.h"
13#include "lib/sys/cpp/component_context.h"
14#include "platform/utils.h"
16
17namespace dart {
18
19char* Utils::StrNDup(const char* s, intptr_t n) {
20 return strndup(s, n);
21}
22
23char* Utils::StrDup(const char* s) {
24 return strdup(s);
25}
26
27intptr_t Utils::StrNLen(const char* s, intptr_t n) {
28 return strnlen(s, n);
29}
30
31int Utils::SNPrint(char* str, size_t size, const char* format, ...) {
32 va_list args;
34 int retval = VSNPrint(str, size, format, args);
35 va_end(args);
36 return retval;
37}
38
39int Utils::VSNPrint(char* str, size_t size, const char* format, va_list args) {
40 int retval = vsnprintf(str, size, format, args);
41 if (retval < 0) {
42 FATAL("Fatal error in Utils::VSNPrint with format '%s'", format);
43 }
44 return retval;
45}
46
47int Utils::Close(int fildes) {
48 return close(fildes);
49}
50size_t Utils::Read(int filedes, void* buf, size_t nbyte) {
51 return read(filedes, buf, nbyte);
52}
53int Utils::Unlink(const char* path) {
54 return unlink(path);
55}
56
57sys::ComponentContext* ComponentContext() {
58 static std::unique_ptr<sys::ComponentContext> context =
59 sys::ComponentContext::CreateAndServeOutgoingDirectory();
60 return context.get();
61}
62
63std::unique_ptr<inspect::Node> vm_node;
64void SetDartVmNode(std::unique_ptr<inspect::Node> node) {
65 vm_node = std::move(node);
66}
67
68std::unique_ptr<inspect::Node> TakeDartVmNode() {
69 // TODO(fxbug.dev/69558) Remove the creation of the node_ from this call
70 // after the runners have been migrated to injecting this object.
71 if (vm_node == nullptr) {
72 static std::unique_ptr<inspect::ComponentInspector> component_inspector =
73 std::make_unique<inspect::ComponentInspector>(
74 async_get_default_dispatcher(), inspect::PublishOptions{});
75 vm_node = std::make_unique<inspect::Node>(
76 component_inspector->root().CreateChild("vm"));
77 }
78 return std::move(vm_node);
79}
80
81} // namespace dart
82
83#endif // defined(DART_HOST_OS_FUCHSIA)
static bool read(SkStream *stream, void *buffer, size_t amount)
static int SNPrint(char *str, size_t size, const char *format,...) PRINTF_ATTRIBUTE(3
static char * StrDup(const char *s)
static int static int VSNPrint(char *str, size_t size, const char *format, va_list args)
static size_t Read(int filedes, void *buf, size_t nbyte)
static intptr_t StrNLen(const char *s, intptr_t n)
static int Close(int fildes)
static int Unlink(const char *path)
static char * StrNDup(const char *s, intptr_t n)
struct MyStruct s
#define FATAL(error)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
uint32_t uint32_t * format
va_start(args, format)
va_end(args)
void SetDartVmNode(std::unique_ptr< inspect::Node > node)
sys::ComponentContext * ComponentContext()
std::unique_ptr< inspect::Node > TakeDartVmNode()
char * strdup(const char *str1)