b71e57617e
This is required by some shell systems, such as Emacs. BUG=https://code.google.com/p/dart/issues/detail?id=14301 R=sgjesse@google.com Review URL: https://codereview.chromium.org//59393003 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@29895 260f80e4-7a28-3924-810f-c04153c831b5
91 lines
2.0 KiB
C++
91 lines
2.0 KiB
C++
// 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.
|
|
|
|
#include "platform/globals.h"
|
|
#if defined(TARGET_OS_LINUX)
|
|
|
|
#include "bin/platform.h"
|
|
|
|
#include <signal.h> // NOLINT
|
|
#include <string.h> // NOLINT
|
|
#include <unistd.h> // NOLINT
|
|
|
|
#include "bin/fdutils.h"
|
|
|
|
|
|
namespace dart {
|
|
namespace bin {
|
|
|
|
bool Platform::Initialize() {
|
|
// Turn off the signal handler for SIGPIPE as it causes the process
|
|
// to terminate on writing to a closed pipe. Without the signal
|
|
// handler error EPIPE is set instead.
|
|
struct sigaction act;
|
|
bzero(&act, sizeof(act));
|
|
act.sa_handler = SIG_IGN;
|
|
if (sigaction(SIGPIPE, &act, 0) != 0) {
|
|
perror("Setting signal handler failed");
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
int Platform::NumberOfProcessors() {
|
|
return sysconf(_SC_NPROCESSORS_ONLN);
|
|
}
|
|
|
|
|
|
const char* Platform::OperatingSystem() {
|
|
return "linux";
|
|
}
|
|
|
|
|
|
bool Platform::LocalHostname(char *buffer, intptr_t buffer_length) {
|
|
return gethostname(buffer, buffer_length) == 0;
|
|
}
|
|
|
|
|
|
char** Platform::Environment(intptr_t* count) {
|
|
// Using environ directly is only safe as long as we do not
|
|
// provide access to modifying environment variables.
|
|
intptr_t i = 0;
|
|
char** tmp = environ;
|
|
while (*(tmp++) != NULL) i++;
|
|
*count = i;
|
|
char** result = new char*[i];
|
|
for (intptr_t current = 0; current < i; current++) {
|
|
result[current] = environ[current];
|
|
}
|
|
return result;
|
|
}
|
|
|
|
|
|
void Platform::FreeEnvironment(char** env, intptr_t count) {
|
|
delete[] env;
|
|
}
|
|
|
|
|
|
void Platform::PrintBlocking(FILE* file, const char* format, ...) {
|
|
int fd = fileno(file);
|
|
FDUtils::SetBlocking(fd);
|
|
va_list args;
|
|
va_start(args, format);
|
|
vfprintf(file, format, args);
|
|
fflush(file);
|
|
va_end(args);
|
|
FDUtils::SetNonBlocking(fd);
|
|
}
|
|
|
|
|
|
void Platform::Cleanup() {
|
|
FDUtils::SetBlocking(fileno(stdout));
|
|
FDUtils::SetBlocking(fileno(stderr));
|
|
}
|
|
|
|
} // namespace bin
|
|
} // namespace dart
|
|
|
|
#endif // defined(TARGET_OS_LINUX)
|