summaryrefslogtreecommitdiff
path: root/drivers/unix/os_unix.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/unix/os_unix.cpp')
-rw-r--r--drivers/unix/os_unix.cpp80
1 files changed, 33 insertions, 47 deletions
diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp
index 53c60951b7..083cd64116 100644
--- a/drivers/unix/os_unix.cpp
+++ b/drivers/unix/os_unix.cpp
@@ -91,20 +91,19 @@ static void _setup_clock() {
#endif
void OS_Unix::debug_break() {
-
assert(false);
};
static void handle_interrupt(int sig) {
- if (!EngineDebugger::is_active())
+ if (!EngineDebugger::is_active()) {
return;
+ }
EngineDebugger::get_script_debugger()->set_depth(-1);
EngineDebugger::get_script_debugger()->set_lines_left(1);
}
void OS_Unix::initialize_debugging() {
-
if (EngineDebugger::is_active()) {
struct sigaction action;
memset(&action, 0, sizeof(action));
@@ -114,12 +113,10 @@ void OS_Unix::initialize_debugging() {
}
int OS_Unix::unix_initialize_audio(int p_audio_driver) {
-
return 0;
}
void OS_Unix::initialize_core() {
-
#ifdef NO_THREADS
ThreadDummy::make_default();
RWLockDummy::make_default();
@@ -144,17 +141,14 @@ void OS_Unix::initialize_core() {
}
void OS_Unix::finalize_core() {
-
NetSocketPosix::cleanup();
}
void OS_Unix::alert(const String &p_alert, const String &p_title) {
-
fprintf(stderr, "ERROR: %s\n", p_alert.utf8().get_data());
}
String OS_Unix::get_stdin_string(bool p_block) {
-
if (p_block) {
char buff[1024];
String ret = stdin_buf + fgets(buff, 1024, stdin);
@@ -166,12 +160,10 @@ String OS_Unix::get_stdin_string(bool p_block) {
}
String OS_Unix::get_name() const {
-
return "Unix";
}
uint64_t OS_Unix::get_unix_time() const {
-
return time(nullptr);
};
@@ -188,13 +180,13 @@ uint64_t OS_Unix::get_system_time_msecs() const {
}
OS::Date OS_Unix::get_date(bool utc) const {
-
time_t t = time(nullptr);
struct tm *lt;
- if (utc)
+ if (utc) {
lt = gmtime(&t);
- else
+ } else {
lt = localtime(&t);
+ }
Date ret;
ret.year = 1900 + lt->tm_year;
// Index starting at 1 to match OS_Unix::get_date
@@ -211,10 +203,11 @@ OS::Date OS_Unix::get_date(bool utc) const {
OS::Time OS_Unix::get_time(bool utc) const {
time_t t = time(nullptr);
struct tm *lt;
- if (utc)
+ if (utc) {
lt = gmtime(&t);
- else
+ } else {
lt = localtime(&t);
+ }
Time ret;
ret.hour = lt->tm_hour;
ret.min = lt->tm_min;
@@ -241,22 +234,22 @@ OS::TimeZoneInfo OS_Unix::get_time_zone_info() const {
// convert from ISO 8601 (1 minute=1, 1 hour=100) to minutes
int hour = (int)bias / 100;
int minutes = bias % 100;
- if (bias < 0)
+ if (bias < 0) {
ret.bias = hour * 60 - minutes;
- else
+ } else {
ret.bias = hour * 60 + minutes;
+ }
return ret;
}
void OS_Unix::delay_usec(uint32_t p_usec) const {
-
struct timespec rem = { static_cast<time_t>(p_usec / 1000000), (static_cast<long>(p_usec) % 1000000) * 1000 };
while (nanosleep(&rem, &rem) == EINTR) {
}
}
-uint64_t OS_Unix::get_ticks_usec() const {
+uint64_t OS_Unix::get_ticks_usec() const {
#if defined(__APPLE__)
uint64_t longtime = mach_absolute_time() * _clock_scale;
#else
@@ -272,19 +265,16 @@ uint64_t OS_Unix::get_ticks_usec() const {
}
Error OS_Unix::execute(const String &p_path, const List<String> &p_arguments, bool p_blocking, ProcessID *r_child_id, String *r_pipe, int *r_exitcode, bool read_stderr, Mutex *p_pipe_mutex) {
-
#ifdef __EMSCRIPTEN__
// Don't compile this code at all to avoid undefined references.
// Actual virtual call goes to OS_JavaScript.
ERR_FAIL_V(ERR_BUG);
#else
if (p_blocking && r_pipe) {
-
String argss;
argss = "\"" + p_path + "\"";
for (int i = 0; i < p_arguments.size(); i++) {
-
argss += String(" \"") + p_arguments[i] + "\"";
}
@@ -300,7 +290,6 @@ Error OS_Unix::execute(const String &p_path, const List<String> &p_arguments, bo
char buf[65535];
while (fgets(buf, 65535, f)) {
-
if (p_pipe_mutex) {
p_pipe_mutex->lock();
}
@@ -310,8 +299,9 @@ Error OS_Unix::execute(const String &p_path, const List<String> &p_arguments, bo
}
}
int rv = pclose(f);
- if (r_exitcode)
+ if (r_exitcode) {
*r_exitcode = WEXITSTATUS(rv);
+ }
return OK;
}
@@ -330,12 +320,14 @@ Error OS_Unix::execute(const String &p_path, const List<String> &p_arguments, bo
Vector<CharString> cs;
cs.push_back(p_path.utf8());
- for (int i = 0; i < p_arguments.size(); i++)
+ for (int i = 0; i < p_arguments.size(); i++) {
cs.push_back(p_arguments[i].utf8());
+ }
Vector<char *> args;
- for (int i = 0; i < cs.size(); i++)
+ for (int i = 0; i < cs.size(); i++) {
args.push_back((char *)cs[i].get_data());
+ }
args.push_back(0);
execvp(p_path.utf8().get_data(), &args[0]);
@@ -345,16 +337,16 @@ Error OS_Unix::execute(const String &p_path, const List<String> &p_arguments, bo
}
if (p_blocking) {
-
int status;
waitpid(pid, &status, 0);
- if (r_exitcode)
+ if (r_exitcode) {
*r_exitcode = WEXITSTATUS(status);
+ }
} else {
-
- if (r_child_id)
+ if (r_child_id) {
*r_child_id = pid;
+ }
}
return OK;
@@ -362,7 +354,6 @@ Error OS_Unix::execute(const String &p_path, const List<String> &p_arguments, bo
}
Error OS_Unix::kill(const ProcessID &p_pid) {
-
int ret = ::kill(p_pid, SIGKILL);
if (!ret) {
//avoid zombie process
@@ -373,29 +364,27 @@ Error OS_Unix::kill(const ProcessID &p_pid) {
}
int OS_Unix::get_process_id() const {
-
return getpid();
};
bool OS_Unix::has_environment(const String &p_var) const {
-
return getenv(p_var.utf8().get_data()) != nullptr;
}
String OS_Unix::get_locale() const {
-
- if (!has_environment("LANG"))
+ if (!has_environment("LANG")) {
return "en";
+ }
String locale = get_environment("LANG");
int tp = locale.find(".");
- if (tp != -1)
+ if (tp != -1) {
locale = locale.substr(0, tp);
+ }
return locale;
}
Error OS_Unix::open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path) {
-
String path = p_path;
if (FileAccess::exists(path) && path.is_rel_path()) {
@@ -442,32 +431,29 @@ Error OS_Unix::get_dynamic_library_symbol_handle(void *p_library_handle, const S
}
Error OS_Unix::set_cwd(const String &p_cwd) {
-
- if (chdir(p_cwd.utf8().get_data()) != 0)
+ if (chdir(p_cwd.utf8().get_data()) != 0) {
return ERR_CANT_OPEN;
+ }
return OK;
}
String OS_Unix::get_environment(const String &p_var) const {
-
- if (getenv(p_var.utf8().get_data()))
+ if (getenv(p_var.utf8().get_data())) {
return getenv(p_var.utf8().get_data());
+ }
return "";
}
bool OS_Unix::set_environment(const String &p_var, const String &p_value) const {
-
return setenv(p_var.utf8().get_data(), p_value.utf8().get_data(), /* overwrite: */ true) == 0;
}
int OS_Unix::get_processor_count() const {
-
return sysconf(_SC_NPROCESSORS_CONF);
}
String OS_Unix::get_user_data_dir() const {
-
String appname = get_safe_dir_name(ProjectSettings::get_singleton()->get("application/config/name"));
if (appname != "") {
bool use_custom_dir = ProjectSettings::get_singleton()->get("application/config/use_custom_user_dir");
@@ -486,7 +472,6 @@ String OS_Unix::get_user_data_dir() const {
}
String OS_Unix::get_executable_path() const {
-
#ifdef __linux__
//fix for running from a symlink
char buf[256];
@@ -544,10 +529,11 @@ void UnixTerminalLogger::log_error(const char *p_function, const char *p_file, i
}
const char *err_details;
- if (p_rationale && p_rationale[0])
+ if (p_rationale && p_rationale[0]) {
err_details = p_rationale;
- else
+ } else {
err_details = p_code;
+ }
// Disable color codes if stdout is not a TTY.
// This prevents Godot from writing ANSI escape codes when redirecting