summaryrefslogtreecommitdiff
path: root/core/os
diff options
context:
space:
mode:
Diffstat (limited to 'core/os')
-rw-r--r--core/os/copymem.h50
-rw-r--r--core/os/dir_access.h4
-rw-r--r--core/os/file_access.cpp20
-rw-r--r--core/os/file_access.h12
-rw-r--r--core/os/keyboard.cpp6
-rw-r--r--core/os/keyboard.h4
-rw-r--r--core/os/memory.cpp1
-rw-r--r--core/os/os.cpp28
-rw-r--r--core/os/os.h7
-rw-r--r--core/os/pool_allocator.cpp3
10 files changed, 60 insertions, 75 deletions
diff --git a/core/os/copymem.h b/core/os/copymem.h
deleted file mode 100644
index 6fd559356c..0000000000
--- a/core/os/copymem.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*************************************************************************/
-/* copymem.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-
-#ifndef COPYMEM_H
-#define COPYMEM_H
-
-#include "core/typedefs.h"
-
-#ifdef PLATFORM_COPYMEM
-
-#include "platform_copymem.h" // included from platform/<current_platform>/platform_copymem.h"
-
-#else
-
-#include <string.h>
-
-#define copymem(to, from, count) memcpy(to, from, count)
-#define zeromem(to, count) memset(to, 0, count)
-#define movemem(to, from, count) memmove(to, from, count)
-
-#endif
-
-#endif // COPYMEM_H
diff --git a/core/os/dir_access.h b/core/os/dir_access.h
index c49c4cc4b8..ec738d30d5 100644
--- a/core/os/dir_access.h
+++ b/core/os/dir_access.h
@@ -84,8 +84,10 @@ public:
virtual bool file_exists(String p_file) = 0;
virtual bool dir_exists(String p_dir) = 0;
+ virtual bool is_readable(String p_dir) { return true; };
+ virtual bool is_writable(String p_dir) { return true; };
static bool exists(String p_dir);
- virtual size_t get_space_left() = 0;
+ virtual uint64_t get_space_left() = 0;
Error copy_dir(String p_from, String p_to, int p_chmod_flags = -1);
virtual Error copy(String p_from, String p_to, int p_chmod_flags = -1);
diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp
index ad234c2d49..d00d0ac5bb 100644
--- a/core/os/file_access.cpp
+++ b/core/os/file_access.cpp
@@ -367,10 +367,10 @@ Vector<String> FileAccess::get_csv_line(const String &p_delim) const {
return strings;
}
-int FileAccess::get_buffer(uint8_t *p_dst, int p_length) const {
+uint64_t FileAccess::get_buffer(uint8_t *p_dst, uint64_t p_length) const {
ERR_FAIL_COND_V(!p_dst && p_length > 0, -1);
- ERR_FAIL_COND_V(p_length < 0, -1);
- int i = 0;
+
+ uint64_t i = 0;
for (i = 0; i < p_length && !eof_reached(); i++) {
p_dst[i] = get_8();
}
@@ -380,11 +380,11 @@ int FileAccess::get_buffer(uint8_t *p_dst, int p_length) const {
String FileAccess::get_as_utf8_string() const {
Vector<uint8_t> sourcef;
- int len = get_len();
+ uint64_t len = get_len();
sourcef.resize(len + 1);
uint8_t *w = sourcef.ptrw();
- int r = get_buffer(w, len);
+ uint64_t r = get_buffer(w, len);
ERR_FAIL_COND_V(r != len, String());
w[len] = 0;
@@ -550,8 +550,8 @@ void FileAccess::store_csv_line(const Vector<String> &p_values, const String &p_
store_line(line);
}
-void FileAccess::store_buffer(const uint8_t *p_src, int p_length) {
- for (int i = 0; i < p_length; i++) {
+void FileAccess::store_buffer(const uint8_t *p_src, uint64_t p_length) {
+ for (uint64_t i = 0; i < p_length; i++) {
store_8(p_src[i]);
}
}
@@ -601,7 +601,7 @@ String FileAccess::get_md5(const String &p_file) {
unsigned char step[32768];
while (true) {
- int br = f->get_buffer(step, 32768);
+ uint64_t br = f->get_buffer(step, 32768);
if (br > 0) {
ctx.update(step, br);
}
@@ -629,7 +629,7 @@ String FileAccess::get_multiple_md5(const Vector<String> &p_file) {
unsigned char step[32768];
while (true) {
- int br = f->get_buffer(step, 32768);
+ uint64_t br = f->get_buffer(step, 32768);
if (br > 0) {
ctx.update(step, br);
}
@@ -658,7 +658,7 @@ String FileAccess::get_sha256(const String &p_file) {
unsigned char step[32768];
while (true) {
- int br = f->get_buffer(step, 32768);
+ uint64_t br = f->get_buffer(step, 32768);
if (br > 0) {
ctx.update(step, br);
}
diff --git a/core/os/file_access.h b/core/os/file_access.h
index 1c78204c1d..f9749c0fd1 100644
--- a/core/os/file_access.h
+++ b/core/os/file_access.h
@@ -93,10 +93,10 @@ public:
virtual String get_path() const { return ""; } /// returns the path for the current open file
virtual String get_path_absolute() const { return ""; } /// returns the absolute path for the current open file
- virtual void seek(size_t p_position) = 0; ///< seek to a given position
- virtual void seek_end(int64_t p_position = 0) = 0; ///< seek from the end of file
- virtual size_t get_position() const = 0; ///< get position in the file
- virtual size_t get_len() const = 0; ///< get size of the file
+ virtual void seek(uint64_t p_position) = 0; ///< seek to a given position
+ virtual void seek_end(int64_t p_position = 0) = 0; ///< seek from the end of file with negative offset
+ virtual uint64_t get_position() const = 0; ///< get position in the file
+ virtual uint64_t get_len() const = 0; ///< get size of the file
virtual bool eof_reached() const = 0; ///< reading passed EOF
@@ -109,7 +109,7 @@ public:
virtual double get_double() const;
virtual real_t get_real() const;
- virtual int get_buffer(uint8_t *p_dst, int p_length) const; ///< get an array of bytes
+ virtual uint64_t get_buffer(uint8_t *p_dst, uint64_t p_length) const; ///< get an array of bytes
virtual String get_line() const;
virtual String get_token() const;
virtual Vector<String> get_csv_line(const String &p_delim = ",") const;
@@ -142,7 +142,7 @@ public:
virtual void store_pascal_string(const String &p_string);
virtual String get_pascal_string();
- virtual void store_buffer(const uint8_t *p_src, int p_length); ///< store an array of bytes
+ virtual void store_buffer(const uint8_t *p_src, uint64_t p_length); ///< store an array of bytes
virtual bool file_exists(const String &p_name) = 0; ///< return true if a file exists
diff --git a/core/os/keyboard.cpp b/core/os/keyboard.cpp
index 4b2cafd8fe..4c5f0b5220 100644
--- a/core/os/keyboard.cpp
+++ b/core/os/keyboard.cpp
@@ -60,7 +60,7 @@ static const _KeyCodeText _keycodes[] = {
{KEY_PAGEUP ,"PageUp"},
{KEY_PAGEDOWN ,"PageDown"},
{KEY_SHIFT ,"Shift"},
- {KEY_CONTROL ,"Control"},
+ {KEY_CTRL ,"Ctrl"},
#ifdef OSX_ENABLED
{KEY_META ,"Command"},
#else
@@ -314,7 +314,7 @@ bool keycode_has_unicode(uint32_t p_keycode) {
case KEY_PAGEUP:
case KEY_PAGEDOWN:
case KEY_SHIFT:
- case KEY_CONTROL:
+ case KEY_CTRL:
case KEY_META:
case KEY_ALT:
case KEY_CAPSLOCK:
@@ -401,7 +401,7 @@ String keycode_get_string(uint32_t p_code) {
codestr += "+";
}
if (p_code & KEY_MASK_CTRL) {
- codestr += find_keycode_name(KEY_CONTROL);
+ codestr += find_keycode_name(KEY_CTRL);
codestr += "+";
}
if (p_code & KEY_MASK_META) {
diff --git a/core/os/keyboard.h b/core/os/keyboard.h
index 3ef70e786f..33f9213c4e 100644
--- a/core/os/keyboard.h
+++ b/core/os/keyboard.h
@@ -45,7 +45,7 @@ enum {
SPKEY = (1 << 24)
};
-enum KeyList {
+enum Key {
/* CURSOR/FUNCTION/BROWSER/MULTIMEDIA/MISC KEYS */
KEY_ESCAPE = SPKEY | 0x01,
KEY_TAB = SPKEY | 0x02,
@@ -68,7 +68,7 @@ enum KeyList {
KEY_PAGEUP = SPKEY | 0x13,
KEY_PAGEDOWN = SPKEY | 0x14,
KEY_SHIFT = SPKEY | 0x15,
- KEY_CONTROL = SPKEY | 0x16,
+ KEY_CTRL = SPKEY | 0x16,
KEY_META = SPKEY | 0x17,
KEY_ALT = SPKEY | 0x18,
KEY_CAPSLOCK = SPKEY | 0x19,
diff --git a/core/os/memory.cpp b/core/os/memory.cpp
index 5910cb0e7b..a756c1d5dd 100644
--- a/core/os/memory.cpp
+++ b/core/os/memory.cpp
@@ -31,7 +31,6 @@
#include "memory.h"
#include "core/error/error_macros.h"
-#include "core/os/copymem.h"
#include "core/templates/safe_refcount.h"
#include <stdio.h>
diff --git a/core/os/os.cpp b/core/os/os.cpp
index 182bab4058..ca1b798e11 100644
--- a/core/os/os.cpp
+++ b/core/os/os.cpp
@@ -106,10 +106,18 @@ void OS::add_logger(Logger *p_logger) {
}
void OS::print_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, Logger::ErrorType p_type) {
+ if (!_stderr_enabled) {
+ return;
+ }
+
_logger->log_error(p_function, p_file, p_line, p_code, p_rationale, p_type);
}
void OS::print(const char *p_format, ...) {
+ if (!_stdout_enabled) {
+ return;
+ }
+
va_list argp;
va_start(argp, p_format);
@@ -119,6 +127,10 @@ void OS::print(const char *p_format, ...) {
}
void OS::printerr(const char *p_format, ...) {
+ if (!_stderr_enabled) {
+ return;
+ }
+
va_list argp;
va_start(argp, p_format);
@@ -163,6 +175,22 @@ bool OS::is_stdout_debug_enabled() const {
return _debug_stdout;
}
+bool OS::is_stdout_enabled() const {
+ return _stdout_enabled;
+}
+
+bool OS::is_stderr_enabled() const {
+ return _stderr_enabled;
+}
+
+void OS::set_stdout_enabled(bool p_enabled) {
+ _stdout_enabled = p_enabled;
+}
+
+void OS::set_stderr_enabled(bool p_enabled) {
+ _stderr_enabled = p_enabled;
+}
+
void OS::dump_memory_to_file(const char *p_file) {
//Memory::dump_static_mem_to_file(p_file);
}
diff --git a/core/os/os.h b/core/os/os.h
index e41d788e12..7198607237 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -60,6 +60,8 @@ class OS {
bool _allow_layered = false;
bool _use_vsync;
bool _vsync_via_compositor;
+ bool _stdout_enabled = true;
+ bool _stderr_enabled = true;
char *last_error;
@@ -219,6 +221,11 @@ public:
bool is_stdout_verbose() const;
bool is_stdout_debug_enabled() const;
+ bool is_stdout_enabled() const;
+ bool is_stderr_enabled() const;
+ void set_stdout_enabled(bool p_enabled);
+ void set_stderr_enabled(bool p_enabled);
+
virtual void disable_crash_handler() {}
virtual bool is_disable_crash_handler() const { return false; }
virtual void initialize_debugging() {}
diff --git a/core/os/pool_allocator.cpp b/core/os/pool_allocator.cpp
index 9be3a62e2f..74e9c24e04 100644
--- a/core/os/pool_allocator.cpp
+++ b/core/os/pool_allocator.cpp
@@ -31,7 +31,6 @@
#include "pool_allocator.h"
#include "core/error/error_macros.h"
-#include "core/os/copymem.h"
#include "core/os/memory.h"
#include "core/os/os.h"
#include "core/string/print_string.h"
@@ -42,7 +41,7 @@
do { \
void *_dst = &((unsigned char *)pool)[m_to_pos]; \
void *_src = &((unsigned char *)pool)[(m_entry).pos]; \
- movemem(_dst, _src, aligned((m_entry).len)); \
+ memmove(_dst, _src, aligned((m_entry).len)); \
(m_entry).pos = m_to_pos; \
} while (0);