mirror of
https://github.com/godotengine/godot.git
synced 2025-11-02 14:41:07 +00:00
Make all file access 64-bit (uint64_t)
This changes the types of a big number of variables. General rules: - Using `uint64_t` in general. We also considered `int64_t` but eventually settled on keeping it unsigned, which is also closer to what one would expect with `size_t`/`off_t`. - We only keep `int64_t` for `seek_end` (takes a negative offset from the end) and for the `Variant` bindings, since `Variant::INT` is `int64_t`. This means we only need to guard against passing negative values in `core_bind.cpp`. - Using `uint32_t` integers for concepts not needing such a huge range, like pages, blocks, etc. In addition: - Improve usage of integer types in some related places; namely, `DirAccess`, core binds. Note: - On Windows, `_ftelli64` reports invalid values when using 32-bit MinGW with version < 8.0. This was an upstream bug fixed in 8.0. It breaks support for big files on 32-bit Windows builds made with that toolchain. We might add a workaround. Fixes #44363. Fixes godotengine/godot-proposals#400. Co-authored-by: Rémi Verschelde <rverschelde@gmail.com>
This commit is contained in:
parent
9cc17a8439
commit
469fa47e06
65 changed files with 326 additions and 342 deletions
|
|
@ -184,11 +184,11 @@ String FileAccessUnix::get_path_absolute() const {
|
|||
return path;
|
||||
}
|
||||
|
||||
void FileAccessUnix::seek(size_t p_position) {
|
||||
void FileAccessUnix::seek(uint64_t p_position) {
|
||||
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
|
||||
|
||||
last_error = OK;
|
||||
if (fseek(f, p_position, SEEK_SET)) {
|
||||
if (fseeko(f, p_position, SEEK_SET)) {
|
||||
check_errors();
|
||||
}
|
||||
}
|
||||
|
|
@ -196,15 +196,15 @@ void FileAccessUnix::seek(size_t p_position) {
|
|||
void FileAccessUnix::seek_end(int64_t p_position) {
|
||||
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
|
||||
|
||||
if (fseek(f, p_position, SEEK_END)) {
|
||||
if (fseeko(f, p_position, SEEK_END)) {
|
||||
check_errors();
|
||||
}
|
||||
}
|
||||
|
||||
size_t FileAccessUnix::get_position() const {
|
||||
uint64_t FileAccessUnix::get_position() const {
|
||||
ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
|
||||
|
||||
long pos = ftell(f);
|
||||
int64_t pos = ftello(f);
|
||||
if (pos < 0) {
|
||||
check_errors();
|
||||
ERR_FAIL_V(0);
|
||||
|
|
@ -212,15 +212,15 @@ size_t FileAccessUnix::get_position() const {
|
|||
return pos;
|
||||
}
|
||||
|
||||
size_t FileAccessUnix::get_len() const {
|
||||
uint64_t FileAccessUnix::get_len() const {
|
||||
ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
|
||||
|
||||
long pos = ftell(f);
|
||||
int64_t pos = ftello(f);
|
||||
ERR_FAIL_COND_V(pos < 0, 0);
|
||||
ERR_FAIL_COND_V(fseek(f, 0, SEEK_END), 0);
|
||||
long size = ftell(f);
|
||||
ERR_FAIL_COND_V(fseeko(f, 0, SEEK_END), 0);
|
||||
int64_t size = ftello(f);
|
||||
ERR_FAIL_COND_V(size < 0, 0);
|
||||
ERR_FAIL_COND_V(fseek(f, pos, SEEK_SET), 0);
|
||||
ERR_FAIL_COND_V(fseeko(f, pos, SEEK_SET), 0);
|
||||
|
||||
return size;
|
||||
}
|
||||
|
|
@ -239,11 +239,11 @@ uint8_t FileAccessUnix::get_8() const {
|
|||
return b;
|
||||
}
|
||||
|
||||
int FileAccessUnix::get_buffer(uint8_t *p_dst, int p_length) const {
|
||||
uint64_t FileAccessUnix::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);
|
||||
ERR_FAIL_COND_V_MSG(!f, -1, "File must be opened before use.");
|
||||
int read = fread(p_dst, 1, p_length, f);
|
||||
|
||||
uint64_t read = fread(p_dst, 1, p_length, f);
|
||||
check_errors();
|
||||
return read;
|
||||
};
|
||||
|
|
@ -262,10 +262,10 @@ 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) {
|
||||
void FileAccessUnix::store_buffer(const uint8_t *p_src, uint64_t p_length) {
|
||||
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
|
||||
ERR_FAIL_COND(!p_src);
|
||||
ERR_FAIL_COND((int)fwrite(p_src, 1, p_length, f) != p_length);
|
||||
ERR_FAIL_COND(fwrite(p_src, 1, p_length, f) != p_length);
|
||||
}
|
||||
|
||||
bool FileAccessUnix::file_exists(const String &p_path) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue