Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
utils.h
Go to the documentation of this file.
1// Copyright (c) 2012, 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#ifndef RUNTIME_BIN_UTILS_H_
6#define RUNTIME_BIN_UTILS_H_
7
8#include <stdlib.h>
9#include <string.h>
10
11#include "include/dart_api.h"
12#include "platform/globals.h"
13#include "platform/utils.h"
14
15namespace dart {
16namespace bin {
17
18class OSError {
19 public:
21
24 sub_system_ = sub_system;
25 code_ = code;
26 message_ = nullptr; // SetMessage will free existing message.
27 SetMessage(message);
28 }
29 virtual ~OSError() { free(message_); }
30
31 // Reload this OSError with the current OS error, discarding the previous.
32 void Reload();
33
34 SubSystem sub_system() { return sub_system_; }
35 int code() { return code_; }
36 char* message() { return message_; }
38
39 private:
40 void set_sub_system(SubSystem sub_system) { sub_system_ = sub_system; }
41 void set_code(int code) { code_ = code; }
42 void SetMessage(const char* message) {
43 free(message_);
44 if (message == nullptr) {
45 message_ = nullptr;
46 } else {
47 message_ = Utils::StrDup(message);
48 }
49 }
50
51 SubSystem sub_system_;
52 int code_;
53 char* message_;
54
56};
57
59 public:
60 // The following methods convert the argument if needed. The
61 // conversions are only needed on Windows. If the methods returns a
62 // pointer that is different from the input pointer, the returned
63 // pointer is allocated with malloc and should be freed using free.
64 //
65 // If the len argument is passed then that number of characters are
66 // converted. If len is -1, conversion will stop at the first NUL
67 // character. If result_len is not NUL, it is used to set the number
68 // of characters in the result.
69 //
70 // A return value of `nullptr` indicates that the conversion is not supported,
71 // which is true on all platforms other than Windows.
72 static const char* ConsoleStringToUtf8(const char* str,
73 intptr_t len = -1,
74 intptr_t* result_len = nullptr);
75 static char* ConsoleStringToUtf8(char* str,
76 intptr_t len = -1,
77 intptr_t* result_len = nullptr);
78 static const char* Utf8ToConsoleString(const char* utf8,
79 intptr_t len = -1,
80 intptr_t* result_len = nullptr);
81 static char* Utf8ToConsoleString(char* utf8,
82 intptr_t len = -1,
83 intptr_t* result_len = nullptr);
84
85 private:
86 DISALLOW_ALLOCATION();
88};
89
91 public:
92 // Convert all the arguments to UTF8. On Windows, the arguments are
93 // encoded in the current code page and not UTF8.
94 //
95 // Returns true if the arguments are converted. In that case
96 // each of the arguments need to be deallocated using free.
97 static bool GetUtf8Argv(int argc, char** argv);
98
99 private:
100 DISALLOW_ALLOCATION();
102};
103
105 public:
106 static void InitOnce();
109 static void Sleep(int64_t millis);
110
111 private:
112 DISALLOW_ALLOCATION();
114};
115
116} // namespace bin
117} // namespace dart
118
119#endif // RUNTIME_BIN_UTILS_H_
static char * StrDup(const char *s)
OSError(int code, const char *message, SubSystem sub_system)
Definition utils.h:23
SubSystem sub_system()
Definition utils.h:34
void SetCodeAndMessage(SubSystem sub_system, int code)
char * message()
Definition utils.h:36
virtual ~OSError()
Definition utils.h:29
static bool GetUtf8Argv(int argc, char **argv)
static char * Utf8ToConsoleString(char *utf8, intptr_t len=-1, intptr_t *result_len=nullptr)
static const char * Utf8ToConsoleString(const char *utf8, intptr_t len=-1, intptr_t *result_len=nullptr)
static char * ConsoleStringToUtf8(char *str, intptr_t len=-1, intptr_t *result_len=nullptr)
static const char * ConsoleStringToUtf8(const char *str, intptr_t len=-1, intptr_t *result_len=nullptr)
static void Sleep(int64_t millis)
static int64_t GetCurrentMonotonicMicros()
static int64_t GetCurrentMonotonicMillis()
static void InitOnce()
#define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName)
Definition globals.h:593
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition globals.h:581