Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
utils_linux.cc
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#include "platform/globals.h"
6#if defined(DART_HOST_OS_LINUX)
7
8#include <sys/utsname.h>
9
10#include "platform/utils.h"
12
13namespace dart {
14
15char* Utils::StrNDup(const char* s, intptr_t n) {
16 return strndup(s, n);
17}
18
19char* Utils::StrDup(const char* s) {
20 return strdup(s);
21}
22
23intptr_t Utils::StrNLen(const char* s, intptr_t n) {
24 return strnlen(s, n);
25}
26
27int Utils::SNPrint(char* str, size_t size, const char* format, ...) {
28 va_list args;
30 int retval = VSNPrint(str, size, format, args);
31 va_end(args);
32 return retval;
33}
34
35int Utils::VSNPrint(char* str, size_t size, const char* format, va_list args) {
36 MSAN_UNPOISON(str, size);
37 int retval = vsnprintf(str, size, format, args);
38 if (retval < 0) {
39 FATAL("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}
47
48size_t Utils::Read(int filedes, void* buf, size_t nbyte) {
49 return read(filedes, buf, nbyte);
50}
51
52int Utils::Unlink(const char* path) {
53 return unlink(path);
54}
55
56bool Utils::IsWindowsSubsystemForLinux() {
57 struct utsname info;
58 if (uname(&info) != 0) {
59 return false; // Not sure.
60 }
61
62 // If info.release contains either Microsoft or microsoft then we are
63 // most likely running under WSL.
64 return strstr(info.release, "icrosoft") != nullptr;
65}
66
67} // namespace dart
68
69#endif // defined(DART_HOST_OS_LINUX)
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
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
#define MSAN_UNPOISON(ptr, len)
va_start(args, format)
va_end(args)
char * strdup(const char *str1)