summaryrefslogtreecommitdiff
path: root/drivers/unix
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/unix')
-rw-r--r--drivers/unix/dir_access_unix.cpp3
-rw-r--r--drivers/unix/file_access_unix.cpp24
-rw-r--r--drivers/unix/file_access_unix.h5
-rw-r--r--drivers/unix/ip_unix.cpp6
-rw-r--r--drivers/unix/os_unix.cpp20
-rw-r--r--drivers/unix/os_unix.h6
-rw-r--r--drivers/unix/stream_peer_tcp_posix.cpp23
-rw-r--r--drivers/unix/stream_peer_tcp_posix.h2
-rw-r--r--drivers/unix/tcp_server_posix.cpp17
-rw-r--r--drivers/unix/thread_posix.cpp2
-rw-r--r--drivers/unix/thread_posix.h2
11 files changed, 72 insertions, 38 deletions
diff --git a/drivers/unix/dir_access_unix.cpp b/drivers/unix/dir_access_unix.cpp
index 4a467293fd..5a4be6df4f 100644
--- a/drivers/unix/dir_access_unix.cpp
+++ b/drivers/unix/dir_access_unix.cpp
@@ -244,7 +244,7 @@ static void _get_drives(List<String> *list) {
// Parse only file:// links
if (strncmp(string, "file://", 7) == 0) {
// Strip any unwanted edges on the strings and push_back if it's not a duplicate
- String fpath = String(string + 7).strip_edges();
+ String fpath = String(string + 7).strip_edges().split_spaces()[0].percent_decode();
if (!list->find(fpath)) {
list->push_back(fpath);
}
@@ -361,6 +361,7 @@ Error DirAccessUnix::rename(String p_path, String p_new_path) {
return ::rename(p_path.utf8().get_data(), p_new_path.utf8().get_data()) == 0 ? OK : FAILED;
}
+
Error DirAccessUnix::remove(String p_path) {
if (p_path.is_rel_path())
diff --git a/drivers/unix/file_access_unix.cpp b/drivers/unix/file_access_unix.cpp
index 1ed3999e1e..c25d34125d 100644
--- a/drivers/unix/file_access_unix.cpp
+++ b/drivers/unix/file_access_unix.cpp
@@ -69,6 +69,7 @@ Error FileAccessUnix::_open(const String &p_path, int p_mode_flags) {
fclose(f);
f = NULL;
+ path_src = p_path;
path = fix_path(p_path);
//printf("opening %ls, %i\n", path.c_str(), Memory::get_static_mem_usage());
@@ -135,7 +136,7 @@ void FileAccessUnix::close() {
if (save_path != "") {
//unlink(save_path.utf8().get_data());
- //print_line("renaming..");
+ //print_line("renaming...");
int rename_error = rename((save_path + ".tmp").utf8().get_data(), save_path.utf8().get_data());
if (rename_error && close_fail_notify) {
@@ -152,6 +153,16 @@ bool FileAccessUnix::is_open() const {
return (f != NULL);
}
+String FileAccessUnix::get_path() const {
+
+ return path_src;
+}
+
+String FileAccessUnix::get_path_absolute() const {
+
+ return path;
+}
+
void FileAccessUnix::seek(size_t p_position) {
ERR_FAIL_COND(!f);
@@ -173,7 +184,7 @@ size_t FileAccessUnix::get_position() const {
ERR_FAIL_COND_V(!f, 0);
- int pos = ftell(f);
+ long pos = ftell(f);
if (pos < 0) {
check_errors();
ERR_FAIL_V(0);
@@ -185,10 +196,10 @@ size_t FileAccessUnix::get_len() const {
ERR_FAIL_COND_V(!f, 0);
- int pos = ftell(f);
+ long pos = ftell(f);
ERR_FAIL_COND_V(pos < 0, 0);
ERR_FAIL_COND_V(fseek(f, 0, SEEK_END), 0);
- int size = ftell(f);
+ long size = ftell(f);
ERR_FAIL_COND_V(size < 0, 0);
ERR_FAIL_COND_V(fseek(f, pos, SEEK_SET), 0);
@@ -236,6 +247,11 @@ void FileAccessUnix::store_8(uint8_t p_dest) {
ERR_FAIL_COND(fwrite(&p_dest, 1, 1, f) != 1);
}
+void FileAccessUnix::store_buffer(const uint8_t *p_src, int p_length) {
+ ERR_FAIL_COND(!f);
+ ERR_FAIL_COND(fwrite(p_src, 1, p_length, f) != p_length);
+}
+
bool FileAccessUnix::file_exists(const String &p_path) {
int err;
diff --git a/drivers/unix/file_access_unix.h b/drivers/unix/file_access_unix.h
index 6f792076b8..88bb39fbd1 100644
--- a/drivers/unix/file_access_unix.h
+++ b/drivers/unix/file_access_unix.h
@@ -51,6 +51,7 @@ class FileAccessUnix : public FileAccess {
mutable Error last_error;
String save_path;
String path;
+ String path_src;
static FileAccess *create_libc();
@@ -61,6 +62,9 @@ public:
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
+ virtual String get_path_absolute() const; /// returns the absolute path for the current open file
+
virtual void seek(size_t p_position); ///< seek to a given position
virtual void seek_end(int64_t p_position = 0); ///< seek from the end of file
virtual size_t get_position() const; ///< get position in the file
@@ -75,6 +79,7 @@ public:
virtual void flush();
virtual void store_8(uint8_t p_dest); ///< store a byte
+ virtual void store_buffer(const uint8_t *p_src, int p_length); ///< store an array of bytes
virtual bool file_exists(const String &p_path); ///< return true if a file exists
diff --git a/drivers/unix/ip_unix.cpp b/drivers/unix/ip_unix.cpp
index 032d91f0dc..949609bb9a 100644
--- a/drivers/unix/ip_unix.cpp
+++ b/drivers/unix/ip_unix.cpp
@@ -101,16 +101,18 @@ IP_Address IP_Unix::_resolve_hostname(const String &p_hostname, Type p_type) {
hints.ai_family = AF_UNSPEC;
hints.ai_flags = AI_ADDRCONFIG;
};
- hints.ai_flags &= !AI_NUMERICHOST;
+ hints.ai_flags &= ~AI_NUMERICHOST;
int s = getaddrinfo(p_hostname.utf8().get_data(), NULL, &hints, &result);
if (s != 0) {
- ERR_PRINT("getaddrinfo failed!");
+ ERR_PRINT("getaddrinfo failed! Cannot resolve hostname.");
return IP_Address();
};
if (result == NULL || result->ai_addr == NULL) {
ERR_PRINT("Invalid response from getaddrinfo");
+ if (result)
+ freeaddrinfo(result);
return IP_Address();
};
diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp
index 5f45f06c79..eeb3b31fc2 100644
--- a/drivers/unix/os_unix.cpp
+++ b/drivers/unix/os_unix.cpp
@@ -73,15 +73,6 @@ void OS_Unix::debug_break() {
assert(false);
};
-int OS_Unix::get_audio_driver_count() const {
-
- return 1;
-}
-const char *OS_Unix::get_audio_driver_name(int p_driver) const {
-
- return "dummy";
-}
-
int OS_Unix::unix_initialize_audio(int p_audio_driver) {
return 0;
@@ -98,10 +89,11 @@ void handle_sigchld(int sig) {
void OS_Unix::initialize_core() {
-#ifdef NO_PTHREADS
+#ifdef NO_THREADS
ThreadDummy::make_default();
SemaphoreDummy::make_default();
MutexDummy::make_default();
+ RWLockDummy::make_default();
#else
ThreadPosix::make_default();
SemaphorePosix::make_default();
@@ -296,7 +288,7 @@ Error OS_Unix::execute(const String &p_path, const List<String> &p_arguments, bo
Vector<char *> args;
for (int i = 0; i < cs.size(); i++)
- args.push_back((char *)cs[i].get_data()); // shitty C cast
+ args.push_back((char *)cs[i].get_data());
args.push_back(0);
execvp(p_path.utf8().get_data(), &args[0]);
@@ -357,6 +349,12 @@ Error OS_Unix::open_dynamic_library(const String p_path, void *&p_library_handle
String path = p_path;
+ if (FileAccess::exists(path) && path.is_rel_path()) {
+ // dlopen expects a slash, in this case a leading ./ for it to be interpreted as a relative path,
+ // otherwise it will end up searching various system directories for the lib instead and finally failing.
+ path = "./" + path;
+ }
+
if (!FileAccess::exists(path)) {
//this code exists so gdnative can load .so files from within the executable path
path = get_executable_path().get_base_dir().plus_file(p_path.get_file());
diff --git a/drivers/unix/os_unix.h b/drivers/unix/os_unix.h
index a7c9015330..db0fe1e00b 100644
--- a/drivers/unix/os_unix.h
+++ b/drivers/unix/os_unix.h
@@ -48,12 +48,6 @@ protected:
// UNIX only handles the core functions.
// inheriting platforms under unix (eg. X11) should handle the rest
- //virtual int get_video_driver_count() const;
- //virtual const char * get_video_driver_name(int p_driver) const;
-
- virtual int get_audio_driver_count() const;
- virtual const char *get_audio_driver_name(int p_driver) const;
-
virtual void initialize_core();
virtual int unix_initialize_audio(int p_audio_driver);
//virtual Error initialize(int p_video_driver,int p_audio_driver);
diff --git a/drivers/unix/stream_peer_tcp_posix.cpp b/drivers/unix/stream_peer_tcp_posix.cpp
index ba9481d36b..6d798f32f9 100644
--- a/drivers/unix/stream_peer_tcp_posix.cpp
+++ b/drivers/unix/stream_peer_tcp_posix.cpp
@@ -124,11 +124,14 @@ void StreamPeerTCPPosix::set_socket(int p_sockfd, IP_Address p_host, int p_port,
sock_type = p_sock_type;
sockfd = p_sockfd;
#ifndef NO_FCNTL
- fcntl(sockfd, F_SETFL, O_NONBLOCK);
+ if (fcntl(sockfd, F_SETFL, O_NONBLOCK) < 0) {
+ WARN_PRINT("Error setting socket as non blocking");
+ }
#else
int bval = 1;
- ioctl(sockfd, FIONBIO, &bval);
-
+ if (ioctl(sockfd, FIONBIO, &bval) < 0) {
+ WARN_PRINT("Error setting socket as non blocking");
+ }
#endif
status = STATUS_CONNECTING;
@@ -150,10 +153,14 @@ Error StreamPeerTCPPosix::connect_to_host(const IP_Address &p_host, uint16_t p_p
};
#ifndef NO_FCNTL
- fcntl(sockfd, F_SETFL, O_NONBLOCK);
+ if (fcntl(sockfd, F_SETFL, O_NONBLOCK) < 0) {
+ WARN_PRINT("Error setting socket as non blocking");
+ }
#else
int bval = 1;
- ioctl(sockfd, FIONBIO, &bval);
+ if (ioctl(sockfd, FIONBIO, &bval) < 0) {
+ WARN_PRINT("Error setting socket as non blocking");
+ }
#endif
struct sockaddr_storage their_addr;
@@ -304,11 +311,13 @@ Error StreamPeerTCPPosix::read(uint8_t *p_buffer, int p_bytes, int &r_received,
return OK;
};
-void StreamPeerTCPPosix::set_nodelay(bool p_enabled) {
+void StreamPeerTCPPosix::set_no_delay(bool p_enabled) {
ERR_FAIL_COND(!is_connected_to_host());
int flag = p_enabled ? 1 : 0;
- setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int));
+ if (setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int)) < 0) {
+ ERR_PRINT("Unable to set TCP no delay option");
+ }
}
bool StreamPeerTCPPosix::is_connected_to_host() const {
diff --git a/drivers/unix/stream_peer_tcp_posix.h b/drivers/unix/stream_peer_tcp_posix.h
index 5770ae48f4..bcebe57771 100644
--- a/drivers/unix/stream_peer_tcp_posix.h
+++ b/drivers/unix/stream_peer_tcp_posix.h
@@ -77,7 +77,7 @@ public:
virtual Status get_status() const;
virtual void disconnect_from_host();
- virtual void set_nodelay(bool p_enabled);
+ virtual void set_no_delay(bool p_enabled);
static void make_default();
diff --git a/drivers/unix/tcp_server_posix.cpp b/drivers/unix/tcp_server_posix.cpp
index 07ffe3b00a..67ab981f46 100644
--- a/drivers/unix/tcp_server_posix.cpp
+++ b/drivers/unix/tcp_server_posix.cpp
@@ -91,10 +91,14 @@ Error TCPServerPosix::listen(uint16_t p_port, const IP_Address &p_bind_address)
ERR_FAIL_COND_V(sockfd == -1, FAILED);
#ifndef NO_FCNTL
- fcntl(sockfd, F_SETFL, O_NONBLOCK);
+ if (fcntl(sockfd, F_SETFL, O_NONBLOCK) < 0) {
+ WARN_PRINT("Error setting socket as non blocking");
+ }
#else
int bval = 1;
- ioctl(sockfd, FIONBIO, &bval);
+ if (ioctl(sockfd, FIONBIO, &bval) < 0) {
+ WARN_PRINT("Error setting socket as non blocking");
+ }
#endif
int reuse = 1;
@@ -113,6 +117,7 @@ Error TCPServerPosix::listen(uint16_t p_port, const IP_Address &p_bind_address)
ERR_FAIL_V(FAILED);
};
} else {
+ close(sockfd);
return ERR_ALREADY_IN_USE;
};
@@ -157,10 +162,14 @@ Ref<StreamPeerTCP> TCPServerPosix::take_connection() {
int fd = accept(listen_sockfd, (struct sockaddr *)&their_addr, &size);
ERR_FAIL_COND_V(fd == -1, Ref<StreamPeerTCP>());
#ifndef NO_FCNTL
- fcntl(fd, F_SETFL, O_NONBLOCK);
+ if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) {
+ WARN_PRINT("Error setting socket as non blocking");
+ }
#else
int bval = 1;
- ioctl(fd, FIONBIO, &bval);
+ if (ioctl(fd, FIONBIO, &bval) < 0) {
+ WARN_PRINT("Error setting socket as non blocking");
+ }
#endif
Ref<StreamPeerTCPPosix> conn = memnew(StreamPeerTCPPosix);
diff --git a/drivers/unix/thread_posix.cpp b/drivers/unix/thread_posix.cpp
index f079ae2ae2..a73b40a6f2 100644
--- a/drivers/unix/thread_posix.cpp
+++ b/drivers/unix/thread_posix.cpp
@@ -31,7 +31,7 @@
#include "thread_posix.h"
#include "script_language.h"
-#if defined(UNIX_ENABLED) || defined(PTHREAD_ENABLED)
+#if (defined(UNIX_ENABLED) || defined(PTHREAD_ENABLED)) && !defined(NO_THREADS)
#ifdef PTHREAD_BSD_SET_NAME
#include <pthread_np.h>
diff --git a/drivers/unix/thread_posix.h b/drivers/unix/thread_posix.h
index 15c9265e6d..ea2de61bd5 100644
--- a/drivers/unix/thread_posix.h
+++ b/drivers/unix/thread_posix.h
@@ -35,7 +35,7 @@
@author Juan Linietsky <reduzio@gmail.com>
*/
-#if defined(UNIX_ENABLED) || defined(PTHREAD_ENABLED)
+#if (defined(UNIX_ENABLED) || defined(PTHREAD_ENABLED)) && !defined(NO_THREADS)
#include "os/thread.h"
#include <pthread.h>