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(HOST_OS_LINUX)
7
8#include "platform/utils.h"
9
10namespace dart {
11
12char* Utils::StrNDup(const char* s, intptr_t n) {
13 return strndup(s, n);
14}
15
16char* Utils::StrDup(const char* s) {
17 return strdup(s);
18}
19
20intptr_t Utils::StrNLen(const char* s, intptr_t n) {
21 return strnlen(s, n);
22}
23
24int Utils::SNPrint(char* str, size_t size, const char* format, ...) {
25 va_list args;
26 va_start(args, format);
27 int retval = VSNPrint(str, size, format, args);
28 va_end(args);
29 return retval;
30}
31
32int Utils::VSNPrint(char* str, size_t size, const char* format, va_list args) {
33 MSAN_UNPOISON(str, size);
34 int retval = vsnprintf(str, size, format, args);
35 if (retval < 0) {
36 FATAL1("Fatal error in Utils::VSNPrint with format '%s'", format);
37 }
38 return retval;
39}
40
41int Utils::Close(int fildes) {
42 return close(fildes);
43}
44size_t Utils::Read(int filedes, void* buf, size_t nbyte) {
45 return read(filedes, buf, nbyte);
46}
47int Utils::Unlink(const char* path) {
48 return unlink(path);
49}
50
51} // namespace dart
52
53#endif // defined(HOST_OS_LINUX)
54