diff options
Diffstat (limited to 'drivers/unix')
-rw-r--r-- | drivers/unix/dir_access_unix.cpp | 4 | ||||
-rw-r--r-- | drivers/unix/dir_access_unix.h | 10 | ||||
-rw-r--r-- | drivers/unix/file_access_unix.cpp | 11 | ||||
-rw-r--r-- | drivers/unix/file_access_unix.h | 4 | ||||
-rw-r--r-- | drivers/unix/ip_unix.cpp | 12 | ||||
-rw-r--r-- | drivers/unix/ip_unix.h | 2 | ||||
-rw-r--r-- | drivers/unix/net_socket_posix.cpp | 2 | ||||
-rw-r--r-- | drivers/unix/os_unix.cpp | 20 | ||||
-rw-r--r-- | drivers/unix/os_unix.h | 3 |
9 files changed, 40 insertions, 28 deletions
diff --git a/drivers/unix/dir_access_unix.cpp b/drivers/unix/dir_access_unix.cpp index af47173b41..7e6105f033 100644 --- a/drivers/unix/dir_access_unix.cpp +++ b/drivers/unix/dir_access_unix.cpp @@ -49,7 +49,7 @@ #include <mntent.h> #endif -DirAccess *DirAccessUnix::create_fs() { +Ref<DirAccess> DirAccessUnix::create_fs() { return memnew(DirAccessUnix); } @@ -374,7 +374,7 @@ Error DirAccessUnix::change_dir(String p_dir) { return OK; } -String DirAccessUnix::get_current_dir(bool p_include_drive) { +String DirAccessUnix::get_current_dir(bool p_include_drive) const { String base = _get_root_path(); if (!base.is_empty()) { String bd = current_dir.replace_first(base, ""); diff --git a/drivers/unix/dir_access_unix.h b/drivers/unix/dir_access_unix.h index f90f55605c..69530de337 100644 --- a/drivers/unix/dir_access_unix.h +++ b/drivers/unix/dir_access_unix.h @@ -41,13 +41,13 @@ #include <unistd.h> class DirAccessUnix : public DirAccess { - DIR *dir_stream; + DIR *dir_stream = nullptr; - static DirAccess *create_fs(); + static Ref<DirAccess> create_fs(); String current_dir; - bool _cisdir; - bool _cishidden; + bool _cisdir = false; + bool _cishidden = false; protected: virtual String fix_unicode_name(const char *p_name) const { return String::utf8(p_name); } @@ -67,7 +67,7 @@ public: virtual bool drives_are_shortcuts(); virtual Error change_dir(String p_dir); ///< can be relative or absolute, return false on success - virtual String get_current_dir(bool p_include_drive = true); ///< return current dir location + virtual String get_current_dir(bool p_include_drive = true) const; ///< return current dir location virtual Error make_dir(String p_dir); virtual bool file_exists(String p_file); diff --git a/drivers/unix/file_access_unix.cpp b/drivers/unix/file_access_unix.cpp index ea442ad8bf..e0b2994b63 100644 --- a/drivers/unix/file_access_unix.cpp +++ b/drivers/unix/file_access_unix.cpp @@ -71,10 +71,7 @@ void FileAccessUnix::check_errors() const { } Error FileAccessUnix::_open(const String &p_path, int p_mode_flags) { - if (f) { - fclose(f); - } - f = nullptr; + _close(); path_src = p_path; path = fix_path(p_path); @@ -148,7 +145,7 @@ Error FileAccessUnix::_open(const String &p_path, int p_mode_flags) { return OK; } -void FileAccessUnix::close() { +void FileAccessUnix::_close() { if (!f) { return; } @@ -336,14 +333,14 @@ Error FileAccessUnix::_set_unix_permissions(const String &p_file, uint32_t p_per return FAILED; } -FileAccess *FileAccessUnix::create_libc() { +Ref<FileAccess> FileAccessUnix::create_libc() { return memnew(FileAccessUnix); } CloseNotificationFunc FileAccessUnix::close_notification_func = nullptr; FileAccessUnix::~FileAccessUnix() { - close(); + _close(); } #endif diff --git a/drivers/unix/file_access_unix.h b/drivers/unix/file_access_unix.h index 8ebdcd2a2d..4340bbbc82 100644 --- a/drivers/unix/file_access_unix.h +++ b/drivers/unix/file_access_unix.h @@ -49,13 +49,13 @@ class FileAccessUnix : public FileAccess { String path; String path_src; - static FileAccess *create_libc(); + static Ref<FileAccess> create_libc(); + void _close(); public: static CloseNotificationFunc close_notification_func; virtual Error _open(const String &p_path, int p_mode_flags); ///< open a file - virtual void close(); ///< close a file virtual bool is_open() const; ///< true when file is open virtual String get_path() const; /// returns the path for the current open file diff --git a/drivers/unix/ip_unix.cpp b/drivers/unix/ip_unix.cpp index d442e521bf..2deeb79957 100644 --- a/drivers/unix/ip_unix.cpp +++ b/drivers/unix/ip_unix.cpp @@ -128,7 +128,7 @@ void IPUnix::_resolve_hostname(List<IPAddress> &r_addresses, const String &p_hos #if defined(UWP_ENABLED) -void IPUnix::get_local_interfaces(Map<String, Interface_Info> *r_interfaces) const { +void IPUnix::get_local_interfaces(HashMap<String, Interface_Info> *r_interfaces) const { using namespace Windows::Networking; using namespace Windows::Networking::Connectivity; @@ -143,7 +143,7 @@ void IPUnix::get_local_interfaces(Map<String, Interface_Info> *r_interfaces) con } String name = hostname->RawName->Data(); - Map<String, Interface_Info>::Element *E = r_interfaces->find(name); + HashMap<String, Interface_Info>::Element *E = r_interfaces->find(name); if (!E) { Interface_Info info; info.name = name; @@ -162,7 +162,7 @@ void IPUnix::get_local_interfaces(Map<String, Interface_Info> *r_interfaces) con #else -void IPUnix::get_local_interfaces(Map<String, Interface_Info> *r_interfaces) const { +void IPUnix::get_local_interfaces(HashMap<String, Interface_Info> *r_interfaces) const { ULONG buf_size = 1024; IP_ADAPTER_ADDRESSES *addrs; @@ -212,7 +212,7 @@ void IPUnix::get_local_interfaces(Map<String, Interface_Info> *r_interfaces) con #else // UNIX -void IPUnix::get_local_interfaces(Map<String, Interface_Info> *r_interfaces) const { +void IPUnix::get_local_interfaces(HashMap<String, Interface_Info> *r_interfaces) const { struct ifaddrs *ifAddrStruct = nullptr; struct ifaddrs *ifa = nullptr; int family; @@ -230,7 +230,7 @@ void IPUnix::get_local_interfaces(Map<String, Interface_Info> *r_interfaces) con continue; } - Map<String, Interface_Info>::Element *E = r_interfaces->find(ifa->ifa_name); + HashMap<String, Interface_Info>::Iterator E = r_interfaces->find(ifa->ifa_name); if (!E) { Interface_Info info; info.name = ifa->ifa_name; @@ -240,7 +240,7 @@ void IPUnix::get_local_interfaces(Map<String, Interface_Info> *r_interfaces) con ERR_CONTINUE(!E); } - Interface_Info &info = E->get(); + Interface_Info &info = E->value; info.ip_addresses.push_front(_sockaddr2ip(ifa->ifa_addr)); } diff --git a/drivers/unix/ip_unix.h b/drivers/unix/ip_unix.h index f0ad01d248..06fcdb6e17 100644 --- a/drivers/unix/ip_unix.h +++ b/drivers/unix/ip_unix.h @@ -43,7 +43,7 @@ class IPUnix : public IP { static IP *_create_unix(); public: - virtual void get_local_interfaces(Map<String, Interface_Info> *r_interfaces) const override; + virtual void get_local_interfaces(HashMap<String, Interface_Info> *r_interfaces) const override; static void make_default(); IPUnix(); diff --git a/drivers/unix/net_socket_posix.cpp b/drivers/unix/net_socket_posix.cpp index 3130d5cae2..f172f31b24 100644 --- a/drivers/unix/net_socket_posix.cpp +++ b/drivers/unix/net_socket_posix.cpp @@ -256,7 +256,7 @@ _FORCE_INLINE_ Error NetSocketPosix::_change_multicast_group(IPAddress p_ip, Str IPAddress if_ip; uint32_t if_v6id = 0; - Map<String, IP::Interface_Info> if_info; + HashMap<String, IP::Interface_Info> if_info; IP::get_singleton()->get_local_interfaces(&if_info); for (KeyValue<String, IP::Interface_Info> &E : if_info) { IP::Interface_Info &c = E.value; diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp index 088525647c..52a4d538e1 100644 --- a/drivers/unix/os_unix.cpp +++ b/drivers/unix/os_unix.cpp @@ -412,6 +412,15 @@ int OS_Unix::get_process_id() const { return getpid(); } +bool OS_Unix::is_process_running(const ProcessID &p_pid) const { + int status = 0; + if (waitpid(p_pid, &status, WNOHANG) != 0) { + return false; + } + + return true; +} + bool OS_Unix::has_environment(const String &p_var) const { return getenv(p_var.utf8().get_data()) != nullptr; } @@ -429,7 +438,7 @@ String OS_Unix::get_locale() const { return locale; } -Error OS_Unix::open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path) { +Error OS_Unix::open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path, String *r_resolved_path) { String path = p_path; if (FileAccess::exists(path) && path.is_relative_path()) { @@ -439,17 +448,22 @@ Error OS_Unix::open_dynamic_library(const String p_path, void *&p_library_handle } if (!FileAccess::exists(path)) { - //this code exists so gdnative can load .so files from within the executable path + // This code exists so GDExtension can load .so files from within the executable path. path = get_executable_path().get_base_dir().plus_file(p_path.get_file()); } if (!FileAccess::exists(path)) { - //this code exists so gdnative can load .so files from a standard unix location + // This code exists so GDExtension can load .so files from a standard unix location. path = get_executable_path().get_base_dir().plus_file("../lib").plus_file(p_path.get_file()); } p_library_handle = dlopen(path.utf8().get_data(), RTLD_NOW); ERR_FAIL_COND_V_MSG(!p_library_handle, ERR_CANT_OPEN, "Can't open dynamic library: " + p_path + ". Error: " + dlerror()); + + if (r_resolved_path != nullptr) { + *r_resolved_path = path; + } + return OK; } diff --git a/drivers/unix/os_unix.h b/drivers/unix/os_unix.h index 460ba4b9e1..a1ed4bd501 100644 --- a/drivers/unix/os_unix.h +++ b/drivers/unix/os_unix.h @@ -55,7 +55,7 @@ public: virtual Error get_entropy(uint8_t *r_buffer, int p_bytes) override; // Should return cryptographycally-safe random bytes. - virtual Error open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path = false) override; + virtual Error open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path = false, String *r_resolved_path = nullptr) override; virtual Error close_dynamic_library(void *p_library_handle) override; virtual Error get_dynamic_library_symbol_handle(void *p_library_handle, const String p_name, void *&p_symbol_handle, bool p_optional = false) override; @@ -76,6 +76,7 @@ public: virtual Error create_process(const String &p_path, const List<String> &p_arguments, ProcessID *r_child_id = nullptr, bool p_open_console = false) override; virtual Error kill(const ProcessID &p_pid) override; virtual int get_process_id() const override; + virtual bool is_process_running(const ProcessID &p_pid) const override; virtual bool has_environment(const String &p_var) const override; virtual String get_environment(const String &p_var) const override; |