diff options
Diffstat (limited to 'drivers/unix')
-rw-r--r-- | drivers/unix/dir_access_unix.cpp | 10 | ||||
-rw-r--r-- | drivers/unix/dir_access_unix.h | 1 | ||||
-rw-r--r-- | drivers/unix/file_access_unix.cpp | 4 | ||||
-rw-r--r-- | drivers/unix/ip_unix.cpp | 2 | ||||
-rw-r--r-- | drivers/unix/ip_unix.h | 4 | ||||
-rw-r--r-- | drivers/unix/net_socket_posix.cpp | 4 | ||||
-rw-r--r-- | drivers/unix/os_unix.cpp | 45 | ||||
-rw-r--r-- | drivers/unix/rw_lock_posix.cpp | 2 | ||||
-rw-r--r-- | drivers/unix/syslog_logger.cpp | 2 | ||||
-rw-r--r-- | drivers/unix/thread_posix.cpp | 10 |
10 files changed, 46 insertions, 38 deletions
diff --git a/drivers/unix/dir_access_unix.cpp b/drivers/unix/dir_access_unix.cpp index 325a88b573..63fa143a03 100644 --- a/drivers/unix/dir_access_unix.cpp +++ b/drivers/unix/dir_access_unix.cpp @@ -32,9 +32,9 @@ #if defined(UNIX_ENABLED) || defined(LIBC_FILEIO_ENABLED) -#include "core/list.h" #include "core/os/memory.h" -#include "core/print_string.h" +#include "core/string/print_string.h" +#include "core/templates/list.h" #include <errno.h> #include <stdio.h> @@ -152,7 +152,7 @@ String DirAccessUnix::get_next() { _cisdir = (entry->d_type == DT_DIR); } - _cishidden = (fname != "." && fname != ".." && fname.begins_with(".")); + _cishidden = is_hidden(fname); return fname; } @@ -400,6 +400,10 @@ String DirAccessUnix::get_filesystem_type() const { return ""; //TODO this should be implemented } +bool DirAccessUnix::is_hidden(const String &p_name) { + return p_name != "." && p_name != ".." && p_name.begins_with("."); +} + DirAccessUnix::DirAccessUnix() { dir_stream = nullptr; _cisdir = false; diff --git a/drivers/unix/dir_access_unix.h b/drivers/unix/dir_access_unix.h index b897efcafc..90f98d4705 100644 --- a/drivers/unix/dir_access_unix.h +++ b/drivers/unix/dir_access_unix.h @@ -51,6 +51,7 @@ class DirAccessUnix : public DirAccess { protected: virtual String fix_unicode_name(const char *p_name) const { return String::utf8(p_name); } + virtual bool is_hidden(const String &p_name); public: virtual Error list_dir_begin(); ///< This starts dir listing diff --git a/drivers/unix/file_access_unix.cpp b/drivers/unix/file_access_unix.cpp index 06bad9f385..ce1e135fe0 100644 --- a/drivers/unix/file_access_unix.cpp +++ b/drivers/unix/file_access_unix.cpp @@ -33,7 +33,7 @@ #if defined(UNIX_ENABLED) || defined(LIBC_FILEIO_ENABLED) #include "core/os/os.h" -#include "core/print_string.h" +#include "core/string/print_string.h" #include <sys/stat.h> #include <sys/types.h> @@ -78,7 +78,7 @@ Error FileAccessUnix::_open(const String &p_path, int p_mode_flags) { path_src = p_path; path = fix_path(p_path); - //printf("opening %ls, %i\n", path.c_str(), Memory::get_static_mem_usage()); + //printf("opening %s, %i\n", path.utf8().get_data(), Memory::get_static_mem_usage()); ERR_FAIL_COND_V_MSG(f, ERR_ALREADY_IN_USE, "File is already in use."); const char *mode_string; diff --git a/drivers/unix/ip_unix.cpp b/drivers/unix/ip_unix.cpp index 05eedccc1d..94ea567c3b 100644 --- a/drivers/unix/ip_unix.cpp +++ b/drivers/unix/ip_unix.cpp @@ -91,7 +91,7 @@ static IP_Address _sockaddr2ip(struct sockaddr *p_addr) { IP_Address IP_Unix::_resolve_hostname(const String &p_hostname, Type p_type) { struct addrinfo hints; - struct addrinfo *result; + struct addrinfo *result = nullptr; memset(&hints, 0, sizeof(struct addrinfo)); if (p_type == TYPE_IPV4) { diff --git a/drivers/unix/ip_unix.h b/drivers/unix/ip_unix.h index 0580facac2..7497f64a53 100644 --- a/drivers/unix/ip_unix.h +++ b/drivers/unix/ip_unix.h @@ -38,12 +38,12 @@ class IP_Unix : public IP { GDCLASS(IP_Unix, IP); - virtual IP_Address _resolve_hostname(const String &p_hostname, IP::Type p_type); + virtual IP_Address _resolve_hostname(const String &p_hostname, IP::Type p_type) override; static IP *_create_unix(); public: - virtual void get_local_interfaces(Map<String, Interface_Info> *r_interfaces) const; + virtual void get_local_interfaces(Map<String, Interface_Info> *r_interfaces) const override; static void make_default(); IP_Unix(); diff --git a/drivers/unix/net_socket_posix.cpp b/drivers/unix/net_socket_posix.cpp index 186804dbb1..0ee97256fc 100644 --- a/drivers/unix/net_socket_posix.cpp +++ b/drivers/unix/net_socket_posix.cpp @@ -348,11 +348,11 @@ Error NetSocketPosix::open(Type p_sock_type, IP::Type &ip_type) { // recv/recvfrom and an ICMP reply was received from a previous send/sendto. unsigned long disable = 0; if (ioctlsocket(_sock, SIO_UDP_CONNRESET, &disable) == SOCKET_ERROR) { - print_verbose("Unable to turn off UDP WSAECONNRESET behaviour on Windows"); + print_verbose("Unable to turn off UDP WSAECONNRESET behavior on Windows"); } if (ioctlsocket(_sock, SIO_UDP_NETRESET, &disable) == SOCKET_ERROR) { // This feature seems not to be supported on wine. - print_verbose("Unable to turn off UDP WSAENETRESET behaviour on Windows"); + print_verbose("Unable to turn off UDP WSAENETRESET behavior on Windows"); } } #endif diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp index 9a5fc6d1a4..318638e5d0 100644 --- a/drivers/unix/os_unix.cpp +++ b/drivers/unix/os_unix.cpp @@ -32,10 +32,10 @@ #ifdef UNIX_ENABLED +#include "core/config/project_settings.h" #include "core/debugger/engine_debugger.h" #include "core/debugger/script_debugger.h" #include "core/os/thread_dummy.h" -#include "core/project_settings.h" #include "drivers/unix/dir_access_unix.h" #include "drivers/unix/file_access_unix.h" #include "drivers/unix/net_socket_posix.h" @@ -48,7 +48,7 @@ #include <mach/mach_time.h> #endif -#if defined(__FreeBSD__) || defined(__OpenBSD__) +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) #include <sys/param.h> #include <sys/sysctl.h> #endif @@ -171,52 +171,53 @@ double OS_Unix::get_unix_time() const { OS::Date OS_Unix::get_date(bool utc) const { time_t t = time(nullptr); - struct tm *lt; + struct tm lt; if (utc) { - lt = gmtime(&t); + gmtime_r(&t, <); } else { - lt = localtime(&t); + localtime_r(&t, <); } Date ret; - ret.year = 1900 + lt->tm_year; + ret.year = 1900 + lt.tm_year; // Index starting at 1 to match OS_Unix::get_date // and Windows SYSTEMTIME and tm_mon follows the typical structure // of 0-11, noted here: http://www.cplusplus.com/reference/ctime/tm/ - ret.month = (Month)(lt->tm_mon + 1); - ret.day = lt->tm_mday; - ret.weekday = (Weekday)lt->tm_wday; - ret.dst = lt->tm_isdst; + ret.month = (Month)(lt.tm_mon + 1); + ret.day = lt.tm_mday; + ret.weekday = (Weekday)lt.tm_wday; + ret.dst = lt.tm_isdst; return ret; } OS::Time OS_Unix::get_time(bool utc) const { time_t t = time(nullptr); - struct tm *lt; + struct tm lt; if (utc) { - lt = gmtime(&t); + gmtime_r(&t, <); } else { - lt = localtime(&t); + localtime_r(&t, <); } Time ret; - ret.hour = lt->tm_hour; - ret.min = lt->tm_min; - ret.sec = lt->tm_sec; + ret.hour = lt.tm_hour; + ret.min = lt.tm_min; + ret.sec = lt.tm_sec; get_time_zone_info(); return ret; } OS::TimeZoneInfo OS_Unix::get_time_zone_info() const { time_t t = time(nullptr); - struct tm *lt = localtime(&t); + struct tm lt; + localtime_r(&t, <); char name[16]; - strftime(name, 16, "%Z", lt); + strftime(name, 16, "%Z", <); name[15] = 0; TimeZoneInfo ret; ret.name = name; char bias_buf[16]; - strftime(bias_buf, 16, "%z", lt); + strftime(bias_buf, 16, "%z", <); int bias; bias_buf[15] = 0; sscanf(bias_buf, "%d", &bias); @@ -323,14 +324,14 @@ Error OS_Unix::execute(const String &p_path, const List<String> &p_arguments, bo execvp(p_path.utf8().get_data(), &args[0]); // still alive? something failed.. fprintf(stderr, "**ERROR** OS_Unix::execute - Could not create child process while executing: %s\n", p_path.utf8().get_data()); - abort(); + raise(SIGKILL); } if (p_blocking) { int status; waitpid(pid, &status, 0); if (r_exitcode) { - *r_exitcode = WEXITSTATUS(status); + *r_exitcode = WIFEXITED(status) ? WEXITSTATUS(status) : status; } } else { @@ -476,7 +477,7 @@ String OS_Unix::get_executable_path() const { return OS::get_executable_path(); } return b; -#elif defined(__OpenBSD__) +#elif defined(__OpenBSD__) || defined(__NetBSD__) char resolved_path[MAXPATHLEN]; realpath(OS::get_executable_path().utf8().get_data(), resolved_path); diff --git a/drivers/unix/rw_lock_posix.cpp b/drivers/unix/rw_lock_posix.cpp index 50b74e84f7..cf24d54c50 100644 --- a/drivers/unix/rw_lock_posix.cpp +++ b/drivers/unix/rw_lock_posix.cpp @@ -32,7 +32,7 @@ #include "rw_lock_posix.h" -#include "core/error_macros.h" +#include "core/error/error_macros.h" #include "core/os/memory.h" #include <stdio.h> diff --git a/drivers/unix/syslog_logger.cpp b/drivers/unix/syslog_logger.cpp index a4c7070f0e..b29d1ec541 100644 --- a/drivers/unix/syslog_logger.cpp +++ b/drivers/unix/syslog_logger.cpp @@ -31,7 +31,7 @@ #ifdef UNIX_ENABLED #include "syslog_logger.h" -#include "core/print_string.h" +#include "core/string/print_string.h" #include <syslog.h> void SyslogLogger::logv(const char *p_format, va_list p_list, bool p_err) { diff --git a/drivers/unix/thread_posix.cpp b/drivers/unix/thread_posix.cpp index aa1b5019ca..f4e3de7646 100644 --- a/drivers/unix/thread_posix.cpp +++ b/drivers/unix/thread_posix.cpp @@ -29,17 +29,17 @@ /*************************************************************************/ #include "thread_posix.h" -#include "core/script_language.h" #if (defined(UNIX_ENABLED) || defined(PTHREAD_ENABLED)) && !defined(NO_THREADS) +#include "core/object/script_language.h" +#include "core/os/memory.h" +#include "core/templates/safe_refcount.h" + #ifdef PTHREAD_BSD_SET_NAME #include <pthread_np.h> #endif -#include "core/os/memory.h" -#include "core/safe_refcount.h" - static void _thread_id_key_destr_callback(void *p_value) { memdelete(static_cast<Thread::ID *>(p_value)); } @@ -126,6 +126,8 @@ Error ThreadPosix::set_name_func_posix(const String &p_name) { #ifdef PTHREAD_BSD_SET_NAME pthread_set_name_np(running_thread, p_name.utf8().get_data()); int err = 0; // Open/FreeBSD ignore errors in this function +#elif defined(PTHREAD_NETBSD_SET_NAME) + int err = pthread_setname_np(running_thread, "%s", const_cast<char *>(p_name.utf8().get_data())); #else int err = pthread_setname_np(running_thread, p_name.utf8().get_data()); #endif // PTHREAD_BSD_SET_NAME |