From 0be6d925dc3c6413bce7a3ccb49631b8e4a6e67a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 14 May 2020 13:23:58 +0200 Subject: Style: clang-format: Disable KeepEmptyLinesAtTheStartOfBlocks Which means that reduz' beloved style which we all became used to will now be changed automatically to remove the first empty line. This makes us lean closer to 1TBS (the one true brace style) instead of hybridating it with some Allman-inspired spacing. There's still the case of braces around single-statement blocks that needs to be addressed (but clang-format can't help with that, but clang-tidy may if we agree about it). Part of #33027. --- drivers/unix/file_access_unix.cpp | 23 ----------------------- 1 file changed, 23 deletions(-) (limited to 'drivers/unix/file_access_unix.cpp') diff --git a/drivers/unix/file_access_unix.cpp b/drivers/unix/file_access_unix.cpp index 54a585c6fd..7edafce9e5 100644 --- a/drivers/unix/file_access_unix.cpp +++ b/drivers/unix/file_access_unix.cpp @@ -63,17 +63,14 @@ #endif void FileAccessUnix::check_errors() const { - ERR_FAIL_COND_MSG(!f, "File must be opened before use."); if (feof(f)) { - last_error = ERR_FILE_EOF; } } Error FileAccessUnix::_open(const String &p_path, int p_mode_flags) { - if (f) fclose(f); f = nullptr; @@ -150,7 +147,6 @@ Error FileAccessUnix::_open(const String &p_path, int p_mode_flags) { } void FileAccessUnix::close() { - if (!f) return; @@ -174,22 +170,18 @@ void FileAccessUnix::close() { } bool FileAccessUnix::is_open() const { - return (f != nullptr); } 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_MSG(!f, "File must be opened before use."); last_error = OK; @@ -198,7 +190,6 @@ 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)) @@ -206,7 +197,6 @@ void FileAccessUnix::seek_end(int64_t p_position) { } size_t FileAccessUnix::get_position() const { - ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); long pos = ftell(f); @@ -218,7 +208,6 @@ size_t FileAccessUnix::get_position() const { } size_t FileAccessUnix::get_len() const { - ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); long pos = ftell(f); @@ -232,12 +221,10 @@ size_t FileAccessUnix::get_len() const { } bool FileAccessUnix::eof_reached() const { - return last_error == ERR_FILE_EOF; } uint8_t FileAccessUnix::get_8() const { - ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); uint8_t b; if (fread(&b, 1, 1, f) == 0) { @@ -248,7 +235,6 @@ uint8_t FileAccessUnix::get_8() const { } int FileAccessUnix::get_buffer(uint8_t *p_dst, int p_length) const { - ERR_FAIL_COND_V_MSG(!f, -1, "File must be opened before use."); int read = fread(p_dst, 1, p_length, f); check_errors(); @@ -256,31 +242,26 @@ int FileAccessUnix::get_buffer(uint8_t *p_dst, int p_length) const { }; Error FileAccessUnix::get_error() const { - return last_error; } void FileAccessUnix::flush() { - ERR_FAIL_COND_MSG(!f, "File must be opened before use."); fflush(f); } void FileAccessUnix::store_8(uint8_t p_dest) { - ERR_FAIL_COND_MSG(!f, "File must be opened before use."); 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_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); } bool FileAccessUnix::file_exists(const String &p_path) { - int err; struct stat st; String filename = fix_path(p_path); @@ -310,7 +291,6 @@ bool FileAccessUnix::file_exists(const String &p_path) { } uint64_t FileAccessUnix::_get_modified_time(const String &p_file) { - String file = fix_path(p_file); struct stat flags; int err = stat(file.utf8().get_data(), &flags); @@ -323,7 +303,6 @@ uint64_t FileAccessUnix::_get_modified_time(const String &p_file) { } uint32_t FileAccessUnix::_get_unix_permissions(const String &p_file) { - String file = fix_path(p_file); struct stat flags; int err = stat(file.utf8().get_data(), &flags); @@ -336,7 +315,6 @@ uint32_t FileAccessUnix::_get_unix_permissions(const String &p_file) { } Error FileAccessUnix::_set_unix_permissions(const String &p_file, uint32_t p_permissions) { - String file = fix_path(p_file); int err = chmod(file.utf8().get_data(), p_permissions); @@ -348,7 +326,6 @@ Error FileAccessUnix::_set_unix_permissions(const String &p_file, uint32_t p_per } FileAccess *FileAccessUnix::create_libc() { - return memnew(FileAccessUnix); } -- cgit v1.2.3 From 0ee0fa42e6639b6fa474b7cf6afc6b1a78142185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 14 May 2020 16:41:43 +0200 Subject: Style: Enforce braces around if blocks and loops Using clang-tidy's `readability-braces-around-statements`. https://clang.llvm.org/extra/clang-tidy/checks/readability-braces-around-statements.html --- drivers/unix/file_access_unix.cpp | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'drivers/unix/file_access_unix.cpp') diff --git a/drivers/unix/file_access_unix.cpp b/drivers/unix/file_access_unix.cpp index 7edafce9e5..06bad9f385 100644 --- a/drivers/unix/file_access_unix.cpp +++ b/drivers/unix/file_access_unix.cpp @@ -71,8 +71,9 @@ void FileAccessUnix::check_errors() const { } Error FileAccessUnix::_open(const String &p_path, int p_mode_flags) { - if (f) + if (f) { fclose(f); + } f = nullptr; path_src = p_path; @@ -82,16 +83,17 @@ Error FileAccessUnix::_open(const String &p_path, int p_mode_flags) { ERR_FAIL_COND_V_MSG(f, ERR_ALREADY_IN_USE, "File is already in use."); const char *mode_string; - if (p_mode_flags == READ) + if (p_mode_flags == READ) { mode_string = "rb"; - else if (p_mode_flags == WRITE) + } else if (p_mode_flags == WRITE) { mode_string = "wb"; - else if (p_mode_flags == READ_WRITE) + } else if (p_mode_flags == READ_WRITE) { mode_string = "rb+"; - else if (p_mode_flags == WRITE_READ) + } else if (p_mode_flags == WRITE_READ) { mode_string = "wb+"; - else + } else { return ERR_INVALID_PARAMETER; + } /* pretty much every implementation that uses fopen as primary backend (unix-compatible mostly) supports utf8 encoding */ @@ -147,8 +149,9 @@ Error FileAccessUnix::_open(const String &p_path, int p_mode_flags) { } void FileAccessUnix::close() { - if (!f) + if (!f) { return; + } fclose(f); f = nullptr; @@ -185,15 +188,17 @@ void FileAccessUnix::seek(size_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 (fseek(f, p_position, SEEK_SET)) { check_errors(); + } } 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 (fseek(f, p_position, SEEK_END)) { check_errors(); + } } size_t FileAccessUnix::get_position() const { @@ -268,13 +273,15 @@ bool FileAccessUnix::file_exists(const String &p_path) { // Does the name exist at all? err = stat(filename.utf8().get_data(), &st); - if (err) + if (err) { return false; + } #ifdef UNIX_ENABLED // See if we have access to the file - if (access(filename.utf8().get_data(), F_OK)) + if (access(filename.utf8().get_data(), F_OK)) { return false; + } #else if (_access(filename.utf8().get_data(), 4) == -1) return false; -- cgit v1.2.3