Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
stdio.cc
Go to the documentation of this file.
1// Copyright (c) 2013, 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 "bin/stdio.h"
6
7#include "bin/builtin.h"
8#include "bin/dartutils.h"
9#include "bin/utils.h"
10
11#include "include/dart_api.h"
12
13#include "platform/globals.h"
14#include "platform/utils.h"
15
16namespace dart {
17namespace bin {
18
20 intptr_t idx,
21 intptr_t* value) {
22 ASSERT(value != nullptr);
23 int64_t v;
25 if (Dart_IsError(status)) {
26 // The caller is expecting an OSError if something goes wrong.
27 OSError os_error(-1, "Invalid argument", OSError::kUnknown);
29 return false;
30 }
31 if ((v < kIntptrMin) || (kIntptrMax < v)) {
32 // The caller is expecting an OSError if something goes wrong.
33 OSError os_error(-1, "Invalid argument", OSError::kUnknown);
35 return false;
36 }
37 *value = static_cast<intptr_t>(v);
38 return true;
39}
40
42 ScopedBlockingCall blocker;
43 intptr_t fd;
44 if (!GetIntptrArgument(args, 0, &fd)) {
45 return;
46 }
47 int byte = -1;
48 if (Stdin::ReadByte(fd, &byte)) {
50 } else {
52 }
53}
54
56 bool enabled = false;
57 intptr_t fd;
58 if (!GetIntptrArgument(args, 0, &fd)) {
59 return;
60 }
61 if (Stdin::GetEchoMode(fd, &enabled)) {
63 } else {
65 }
66}
67
69 intptr_t fd;
70 if (!GetIntptrArgument(args, 0, &fd)) {
71 return;
72 }
73 bool enabled;
74 Dart_Handle status = Dart_GetNativeBooleanArgument(args, 1, &enabled);
75 if (Dart_IsError(status)) {
76 // The caller is expecting an OSError if something goes wrong.
77 OSError os_error(-1, "Invalid argument", OSError::kUnknown);
79 return;
80 }
81 if (Stdin::SetEchoMode(fd, enabled)) {
83 } else {
85 }
86}
87
89 bool enabled = false;
90 intptr_t fd;
91 if (!GetIntptrArgument(args, 0, &fd)) {
92 return;
93 }
94 if (Stdin::GetEchoNewlineMode(fd, &enabled)) {
96 } else {
98 }
99}
100
102 intptr_t fd;
103 if (!GetIntptrArgument(args, 0, &fd)) {
104 return;
105 }
106 bool enabled;
107 Dart_Handle status = Dart_GetNativeBooleanArgument(args, 1, &enabled);
108 if (Dart_IsError(status)) {
109 // The caller is expecting an OSError if something goes wrong.
110 OSError os_error(-1, "Invalid argument", OSError::kUnknown);
112 return;
113 }
114 if (Stdin::SetEchoNewlineMode(fd, enabled)) {
116 } else {
118 }
119}
120
122 bool enabled = false;
123 intptr_t fd;
124 if (!GetIntptrArgument(args, 0, &fd)) {
125 return;
126 }
127 if (Stdin::GetLineMode(fd, &enabled)) {
129 } else {
131 }
132}
133
135 intptr_t fd;
136 if (!GetIntptrArgument(args, 0, &fd)) {
137 return;
138 }
139 bool enabled;
140 Dart_Handle status = Dart_GetNativeBooleanArgument(args, 1, &enabled);
141 if (Dart_IsError(status)) {
142 // The caller is expecting an OSError if something goes wrong.
143 OSError os_error(-1, "Invalid argument", OSError::kUnknown);
145 return;
146 }
147 if (Stdin::SetLineMode(fd, enabled)) {
149 } else {
151 }
152}
153
155 bool supported = false;
156 intptr_t fd;
157 if (!GetIntptrArgument(args, 0, &fd)) {
158 return;
159 }
160 if (Stdin::AnsiSupported(fd, &supported)) {
162 } else {
164 }
165}
166
168 intptr_t fd;
169 if (!GetIntptrArgument(args, 0, &fd)) {
170 return;
171 }
172 int size[2];
173 if (Stdout::GetTerminalSize(fd, size)) {
174 Dart_Handle list = Dart_NewList(2);
175 Dart_ListSetAt(list, 0, Dart_NewInteger(size[0]));
176 Dart_ListSetAt(list, 1, Dart_NewInteger(size[1]));
178 } else {
180 }
181}
182
184 intptr_t fd;
185 if (!GetIntptrArgument(args, 0, &fd)) {
186 return;
187 }
188 bool supported = false;
189 if (Stdout::AnsiSupported(fd, &supported)) {
191 } else {
193 }
194}
195
196} // namespace bin
197} // namespace dart
#define FUNCTION_NAME(name)
Definition builtin.h:19
static Dart_Handle NewDartOSError()
Definition dartutils.cc:706
static bool GetEchoNewlineMode(intptr_t fd, bool *enabled)
static bool GetEchoMode(intptr_t fd, bool *enabled)
static bool SetEchoMode(intptr_t fd, bool enabled)
static bool ReadByte(intptr_t fd, int *byte)
static bool AnsiSupported(intptr_t fd, bool *supported)
static bool SetLineMode(intptr_t fd, bool enabled)
static bool GetLineMode(intptr_t fd, bool *enabled)
static bool SetEchoNewlineMode(intptr_t fd, bool enabled)
static bool GetTerminalSize(intptr_t fd, int size[2])
static bool AnsiSupported(intptr_t fd, bool *supported)
struct _Dart_Handle * Dart_Handle
Definition dart_api.h:258
struct _Dart_NativeArguments * Dart_NativeArguments
Definition dart_api.h:3010
#define ASSERT(E)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
uint8_t value
void FUNCTION_NAME() Stdin_AnsiSupported(Dart_NativeArguments args)
Definition stdio.cc:154
void FUNCTION_NAME() Stdin_SetEchoNewlineMode(Dart_NativeArguments args)
Definition stdio.cc:101
void FUNCTION_NAME() Stdin_GetLineMode(Dart_NativeArguments args)
Definition stdio.cc:121
void FUNCTION_NAME() Stdin_GetEchoMode(Dart_NativeArguments args)
Definition stdio.cc:55
void FUNCTION_NAME() Stdin_SetLineMode(Dart_NativeArguments args)
Definition stdio.cc:134
void FUNCTION_NAME() Stdout_GetTerminalSize(Dart_NativeArguments args)
Definition stdio.cc:167
void FUNCTION_NAME() Stdin_GetEchoNewlineMode(Dart_NativeArguments args)
Definition stdio.cc:88
void FUNCTION_NAME() Stdin_ReadByte(Dart_NativeArguments args)
Definition stdio.cc:41
void FUNCTION_NAME() Stdin_SetEchoMode(Dart_NativeArguments args)
Definition stdio.cc:68
void FUNCTION_NAME() Stdout_AnsiSupported(Dart_NativeArguments args)
Definition stdio.cc:183
static bool GetIntptrArgument(Dart_NativeArguments args, intptr_t idx, intptr_t *value)
Definition stdio.cc:19
DART_EXPORT Dart_Handle Dart_True()
DART_EXPORT void Dart_SetBooleanReturnValue(Dart_NativeArguments args, bool retval)
constexpr intptr_t kIntptrMin
Definition globals.h:556
DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value)
DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, Dart_Handle retval)
DART_EXPORT Dart_Handle Dart_ListSetAt(Dart_Handle list, intptr_t index, Dart_Handle value)
DART_EXPORT bool Dart_IsError(Dart_Handle handle)
DART_EXPORT void Dart_SetIntegerReturnValue(Dart_NativeArguments args, int64_t retval)
DART_EXPORT Dart_Handle Dart_NewList(intptr_t length)
DART_EXPORT Dart_Handle Dart_GetNativeIntegerArgument(Dart_NativeArguments args, int index, int64_t *value)
DART_EXPORT Dart_Handle Dart_GetNativeBooleanArgument(Dart_NativeArguments args, int index, bool *value)
constexpr intptr_t kIntptrMax
Definition globals.h:557