You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-07 12:30:27 +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:
committed by
Rémi Verschelde
parent
74174676b8
commit
817ffc01e1
@@ -47,11 +47,7 @@ godot_int GDAPI godot_videodecoder_file_read(void *ptr, uint8_t *buf, int buf_si
|
||||
|
||||
// if file exists
|
||||
if (file) {
|
||||
long bytes_read = file->get_buffer(buf, buf_size);
|
||||
// No bytes to read => EOF
|
||||
if (bytes_read == 0) {
|
||||
return 0;
|
||||
}
|
||||
int64_t bytes_read = file->get_buffer(buf, buf_size);
|
||||
return bytes_read;
|
||||
}
|
||||
return -1;
|
||||
@@ -62,41 +58,35 @@ int64_t GDAPI godot_videodecoder_file_seek(void *ptr, int64_t pos, int whence) {
|
||||
FileAccess *file = reinterpret_cast<FileAccess *>(ptr);
|
||||
|
||||
if (file) {
|
||||
size_t len = file->get_len();
|
||||
int64_t len = file->get_len();
|
||||
switch (whence) {
|
||||
case SEEK_SET: {
|
||||
// Just for explicitness
|
||||
size_t new_pos = static_cast<size_t>(pos);
|
||||
if (new_pos > len) {
|
||||
if (pos > len) {
|
||||
return -1;
|
||||
}
|
||||
file->seek(new_pos);
|
||||
pos = static_cast<int64_t>(file->get_position());
|
||||
return pos;
|
||||
file->seek(pos);
|
||||
return file->get_position();
|
||||
} break;
|
||||
case SEEK_CUR: {
|
||||
// Just in case it doesn't exist
|
||||
if (pos < 0 && (size_t)-pos > file->get_position()) {
|
||||
if (pos < 0 && -pos > (int64_t)file->get_position()) {
|
||||
return -1;
|
||||
}
|
||||
pos = pos + static_cast<int>(file->get_position());
|
||||
file->seek(pos);
|
||||
pos = static_cast<int64_t>(file->get_position());
|
||||
return pos;
|
||||
file->seek(file->get_position() + pos);
|
||||
return file->get_position();
|
||||
} break;
|
||||
case SEEK_END: {
|
||||
// Just in case something goes wrong
|
||||
if ((size_t)-pos > len) {
|
||||
if (-pos > len) {
|
||||
return -1;
|
||||
}
|
||||
file->seek_end(pos);
|
||||
pos = static_cast<int64_t>(file->get_position());
|
||||
return pos;
|
||||
return file->get_position();
|
||||
} break;
|
||||
default: {
|
||||
// Only 4 possible options, hence default = AVSEEK_SIZE
|
||||
// Asks to return the length of file
|
||||
return static_cast<int64_t>(len);
|
||||
return len;
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user