2012-03-13 13:00:47 +00:00
|
|
|
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
|
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
|
2013-02-20 21:17:38 +00:00
|
|
|
#include "platform/globals.h"
|
2021-07-02 19:06:45 +00:00
|
|
|
#if defined(DART_HOST_OS_MACOS)
|
2013-02-20 21:17:38 +00:00
|
|
|
|
2016-11-04 19:30:56 +00:00
|
|
|
#include <errno.h> // NOLINT
|
|
|
|
#include <mach/clock.h> // NOLINT
|
|
|
|
#include <mach/mach.h> // NOLINT
|
2015-12-11 20:39:56 +00:00
|
|
|
#include <mach/mach_time.h> // NOLINT
|
2016-11-04 19:30:56 +00:00
|
|
|
#include <netdb.h> // NOLINT
|
2016-03-16 17:01:00 +00:00
|
|
|
#include <sys/time.h> // NOLINT
|
2016-11-04 19:30:56 +00:00
|
|
|
#include <time.h> // NOLINT
|
2016-01-11 21:21:46 +00:00
|
|
|
|
2012-03-13 13:00:47 +00:00
|
|
|
#include "bin/utils.h"
|
2012-03-21 09:39:47 +00:00
|
|
|
#include "platform/assert.h"
|
2015-11-19 22:18:52 +00:00
|
|
|
#include "platform/utils.h"
|
2012-03-13 13:00:47 +00:00
|
|
|
|
2013-04-25 14:22:30 +00:00
|
|
|
namespace dart {
|
|
|
|
namespace bin {
|
|
|
|
|
2023-04-12 01:11:05 +00:00
|
|
|
OSError::OSError() : sub_system_(kSystem), code_(0), message_(nullptr) {
|
2018-05-24 02:07:39 +00:00
|
|
|
Reload();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OSError::Reload() {
|
2018-05-24 20:01:51 +00:00
|
|
|
SetCodeAndMessage(kSystem, errno);
|
2012-03-13 13:00:47 +00:00
|
|
|
}
|
2012-03-21 09:39:47 +00:00
|
|
|
|
|
|
|
void OSError::SetCodeAndMessage(SubSystem sub_system, int code) {
|
|
|
|
set_sub_system(sub_system);
|
|
|
|
set_code(code);
|
|
|
|
if (sub_system == kSystem) {
|
2013-08-08 20:24:05 +00:00
|
|
|
const int kBufferSize = 1024;
|
|
|
|
char error_message[kBufferSize];
|
2015-11-19 22:18:52 +00:00
|
|
|
Utils::StrError(code, error_message, kBufferSize);
|
2013-08-08 20:24:05 +00:00
|
|
|
SetMessage(error_message);
|
2012-03-21 09:39:47 +00:00
|
|
|
} else if (sub_system == kGetAddressInfo) {
|
|
|
|
SetMessage(gai_strerror(code));
|
|
|
|
} else {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
2012-11-13 15:03:23 +00:00
|
|
|
|
2016-11-04 19:30:56 +00:00
|
|
|
const char* StringUtils::ConsoleStringToUtf8(const char* str,
|
|
|
|
intptr_t len,
|
|
|
|
intptr_t* result_len) {
|
2023-04-12 01:11:05 +00:00
|
|
|
return nullptr;
|
2012-12-12 14:39:21 +00:00
|
|
|
}
|
|
|
|
|
2016-11-04 19:30:56 +00:00
|
|
|
const char* StringUtils::Utf8ToConsoleString(const char* utf8,
|
|
|
|
intptr_t len,
|
|
|
|
intptr_t* result_len) {
|
2023-04-12 01:11:05 +00:00
|
|
|
return nullptr;
|
2012-12-12 14:39:21 +00:00
|
|
|
}
|
|
|
|
|
2016-11-04 19:30:56 +00:00
|
|
|
char* StringUtils::ConsoleStringToUtf8(char* str,
|
|
|
|
intptr_t len,
|
|
|
|
intptr_t* result_len) {
|
2023-04-12 01:11:05 +00:00
|
|
|
return nullptr;
|
2012-12-12 14:39:21 +00:00
|
|
|
}
|
|
|
|
|
2016-11-04 19:30:56 +00:00
|
|
|
char* StringUtils::Utf8ToConsoleString(char* utf8,
|
|
|
|
intptr_t len,
|
|
|
|
intptr_t* result_len) {
|
2023-04-12 01:11:05 +00:00
|
|
|
return nullptr;
|
2012-12-12 14:39:21 +00:00
|
|
|
}
|
2012-12-13 09:24:05 +00:00
|
|
|
|
2015-06-24 08:36:05 +00:00
|
|
|
bool ShellUtils::GetUtf8Argv(int argc, char** argv) {
|
|
|
|
return false;
|
2012-12-13 09:24:05 +00:00
|
|
|
}
|
2013-02-15 20:51:49 +00:00
|
|
|
|
2024-01-26 18:21:14 +00:00
|
|
|
void TimerUtils::InitOnce() {}
|
2015-12-18 21:20:57 +00:00
|
|
|
|
2015-12-11 20:39:56 +00:00
|
|
|
int64_t TimerUtils::GetCurrentMonotonicMillis() {
|
|
|
|
return GetCurrentMonotonicMicros() / 1000;
|
2013-02-15 20:51:49 +00:00
|
|
|
}
|
|
|
|
|
2015-12-11 20:39:56 +00:00
|
|
|
int64_t TimerUtils::GetCurrentMonotonicMicros() {
|
2024-01-26 18:21:14 +00:00
|
|
|
return clock_gettime_nsec_np(CLOCK_MONOTONIC_RAW) /
|
|
|
|
kNanosecondsPerMicrosecond;
|
2013-02-15 20:51:49 +00:00
|
|
|
}
|
2013-02-20 21:17:38 +00:00
|
|
|
|
2013-04-05 13:04:26 +00:00
|
|
|
void TimerUtils::Sleep(int64_t millis) {
|
2013-12-16 18:52:15 +00:00
|
|
|
struct timespec req; // requested.
|
|
|
|
struct timespec rem; // remainder.
|
|
|
|
int64_t micros = millis * kMicrosecondsPerMillisecond;
|
|
|
|
int64_t seconds = micros / kMicrosecondsPerSecond;
|
|
|
|
micros = micros - seconds * kMicrosecondsPerSecond;
|
|
|
|
int64_t nanos = micros * kNanosecondsPerMicrosecond;
|
|
|
|
req.tv_sec = seconds;
|
|
|
|
req.tv_nsec = nanos;
|
|
|
|
while (true) {
|
|
|
|
int r = nanosleep(&req, &rem);
|
|
|
|
if (r == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// We should only ever see an interrupt error.
|
|
|
|
ASSERT(errno == EINTR);
|
|
|
|
// Copy remainder into requested and repeat.
|
|
|
|
req = rem;
|
2013-11-19 18:26:10 +00:00
|
|
|
}
|
2013-04-05 13:04:26 +00:00
|
|
|
}
|
|
|
|
|
2013-04-25 14:22:30 +00:00
|
|
|
} // namespace bin
|
|
|
|
} // namespace dart
|
|
|
|
|
2021-07-02 19:06:45 +00:00
|
|
|
#endif // defined(DART_HOST_OS_MACOS)
|