From c5e32652f947695b8911aed5d7149491db9cd75d Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Mon, 16 Mar 2026 23:55:14 -0700 Subject: [PATCH] [wpiutil] Rename WPI_kInvalidFile to WPI_INVALID_FILE --- .../native/cpp/DataLogBackgroundWriter.cpp | 14 ++++++------ wpiutil/src/main/native/cpp/fs.cpp | 22 +++++++++---------- .../src/main/native/include/wpi/util/fs.hpp | 14 ++++++------ 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/datalog/src/main/native/cpp/DataLogBackgroundWriter.cpp b/datalog/src/main/native/cpp/DataLogBackgroundWriter.cpp index 18825dd8d2..60bffd70e2 100644 --- a/datalog/src/main/native/cpp/DataLogBackgroundWriter.cpp +++ b/datalog/src/main/native/cpp/DataLogBackgroundWriter.cpp @@ -184,9 +184,9 @@ struct DataLogBackgroundWriter::WriterThreadState { ~WriterThreadState() { Close(); } void Close() { - if (f != WPI_kInvalidFile) { + if (f != WPI_INVALID_FILE) { fs::CloseFile(f); - f = WPI_kInvalidFile; + f = WPI_INVALID_FILE; } } @@ -208,7 +208,7 @@ struct DataLogBackgroundWriter::WriterThreadState { std::string baseFilename; std::string filename; fs::path path; - fs::file_t f = WPI_kInvalidFile; + fs::file_t f = WPI_INVALID_FILE; uintmax_t freeSpace = UINTMAX_MAX; int segmentCount = 1; }; @@ -265,7 +265,7 @@ void DataLogBackgroundWriter::StartLogFile(WriterThreadState& state) { } } - if (state.f == WPI_kInvalidFile) { + if (state.f == WPI_INVALID_FILE) { WPI_ERROR(m_msglog, "Could not open log file, no log being saved"); } else { WPI_INFO(m_msglog, "Logging to '{}' ({} free space)", state.path.string(), @@ -274,7 +274,7 @@ void DataLogBackgroundWriter::StartLogFile(WriterThreadState& state) { } // start file - if (state.f != WPI_kInvalidFile) { + if (state.f != WPI_INVALID_FILE) { StartFile(); } } @@ -348,7 +348,7 @@ void DataLogBackgroundWriter::WriterThreadMain(std::string_view dir) { written = 0; } - if (!m_newFilename.empty() && state.f != WPI_kInvalidFile) { + if (!m_newFilename.empty() && state.f != WPI_INVALID_FILE) { auto newFilename = std::move(m_newFilename); m_newFilename.clear(); // rename @@ -375,7 +375,7 @@ void DataLogBackgroundWriter::WriterThreadMain(std::string_view dir) { continue; } - if (state.f != WPI_kInvalidFile && !blocked) { + if (state.f != WPI_INVALID_FILE && !blocked) { lock.unlock(); // update free space every 10 flushes (in case other things are writing) diff --git a/wpiutil/src/main/native/cpp/fs.cpp b/wpiutil/src/main/native/cpp/fs.cpp index 4f6347299e..150287affc 100644 --- a/wpiutil/src/main/native/cpp/fs.cpp +++ b/wpiutil/src/main/native/cpp/fs.cpp @@ -104,12 +104,12 @@ static file_t openFileInternal(const path& Path, std::error_code& EC, // This only runs if we failed to open the file, so there is probably // no performances issues. if (LastError != ERROR_ACCESS_DENIED) { - return WPI_kInvalidFile; + return WPI_INVALID_FILE; } if (is_directory(Path)) { EC = std::make_error_code(std::errc::is_a_directory); } - return WPI_kInvalidFile; + return WPI_INVALID_FILE; } EC = std::error_code(); return H; @@ -153,14 +153,14 @@ file_t OpenFile(const path& Path, std::error_code& EC, CreationDisposition Disp, DWORD LastError = ::GetLastError(); ::CloseHandle(Result); EC = wpi::util::mapWindowsError(LastError); - return WPI_kInvalidFile; + return WPI_INVALID_FILE; } } if (Flags & OF_Delete) { if ((EC = setDeleteDisposition(Result, true))) { ::CloseHandle(Result); - return WPI_kInvalidFile; + return WPI_INVALID_FILE; } } return Result; @@ -171,7 +171,7 @@ file_t OpenFileForRead(const path& Path, std::error_code& EC, OpenFlags Flags) { } int FileToFd(file_t& F, std::error_code& EC, OpenFlags Flags) { - if (F == WPI_kInvalidFile) { + if (F == WPI_INVALID_FILE) { EC = wpi::util::mapWindowsError(ERROR_INVALID_HANDLE); return -1; } @@ -193,13 +193,13 @@ int FileToFd(file_t& F, std::error_code& EC, OpenFlags Flags) { } EC = std::error_code(); - F = WPI_kInvalidFile; + F = WPI_INVALID_FILE; return ResultFD; } void CloseFile(file_t& F) { ::CloseHandle(F); - F = WPI_kInvalidFile; + F = WPI_INVALID_FILE; } #else // _WIN32 @@ -243,14 +243,14 @@ static int nativeOpenFlags(CreationDisposition Disp, OpenFlags Flags, file_t OpenFile(const path& Path, std::error_code& EC, CreationDisposition Disp, FileAccess Access, OpenFlags Flags, unsigned Mode) { int OpenFlags = nativeOpenFlags(Disp, Flags, Access); - file_t ResultFD = WPI_kInvalidFile; + file_t ResultFD = WPI_INVALID_FILE; // Call ::open in a lambda to avoid overload resolution in RetryAfterSignal // when open is overloaded, such as in Bionic. auto Open = [&]() { return ::open(Path.c_str(), OpenFlags, Mode); }; if ((ResultFD = wpi::util::sys::RetryAfterSignal(-1, Open)) < 0) { EC = std::error_code(errno, std::generic_category()); - return WPI_kInvalidFile; + return WPI_INVALID_FILE; } #ifndef O_CLOEXEC if (!(Flags & OF_ChildInherit)) { @@ -269,14 +269,14 @@ file_t OpenFileForRead(const path& Path, std::error_code& EC, OpenFlags Flags) { int FileToFd(file_t& F, std::error_code& EC, OpenFlags Flags) { int fd = F; - F = WPI_kInvalidFile; + F = WPI_INVALID_FILE; EC = std::error_code(); return fd; } void CloseFile(file_t& F) { ::close(F); - F = WPI_kInvalidFile; + F = WPI_INVALID_FILE; } #endif // _WIN32 diff --git a/wpiutil/src/main/native/include/wpi/util/fs.hpp b/wpiutil/src/main/native/include/wpi/util/fs.hpp index b92d707890..ef72915e7a 100644 --- a/wpiutil/src/main/native/include/wpi/util/fs.hpp +++ b/wpiutil/src/main/native/include/wpi/util/fs.hpp @@ -27,10 +27,10 @@ using fstream = std::fstream; #if defined(_WIN32) // A Win32 HANDLE is a typedef of void* using file_t = void*; -#define WPI_kInvalidFile reinterpret_cast(-1) +#define WPI_INVALID_FILE reinterpret_cast(-1) #else using file_t = int; -#define WPI_kInvalidFile -1 +#define WPI_INVALID_FILE -1 #endif enum CreationDisposition : unsigned { @@ -138,7 +138,7 @@ file_t OpenFile(const path& Path, std::error_code& EC, CreationDisposition Disp, * opened in, for example, read-write or in write-only mode. * @param Mode The access permissions of the file, represented in octal. * @returns a platform-specific file descriptor if \a Name has been opened, - * otherwise WPI_kInvalidFile. + * otherwise WPI_INVALID_FILE. */ inline file_t OpenFileForWrite(const path& Path, std::error_code& EC, CreationDisposition Disp, OpenFlags Flags, @@ -161,7 +161,7 @@ inline file_t OpenFileForWrite(const path& Path, std::error_code& EC, * opened in, for example, read-write or in write-only mode. * @param Mode The access permissions of the file, represented in octal. * @return a platform-specific file descriptor if \a Name has been opened, - * otherwise WPI_kInvalidFile. + * otherwise WPI_INVALID_FILE. */ inline file_t OpenFileForReadWrite(const path& Path, std::error_code& EC, CreationDisposition Disp, OpenFlags Flags, @@ -180,7 +180,7 @@ inline file_t OpenFileForReadWrite(const path& Path, std::error_code& EC, * @param EC Error code output, set to non-zero on error * @param Flags Additional flags * @return a platform-specific file descriptor if \a Name has been opened, - * otherwise WPI_kInvalidFile. + * otherwise WPI_INVALID_FILE. */ file_t OpenFileForRead(const path& Path, std::error_code& EC, OpenFlags Flags = OF_None); @@ -190,7 +190,7 @@ file_t OpenFileForRead(const path& Path, std::error_code& EC, * must be closed with ::close() instead of CloseFile(). * * @param F On input, this is the file to convert to a file descriptor. - * On output, the file is set to WPI_kInvalidFile. + * On output, the file is set to WPI_INVALID_FILE. * @param EC Error code output, set to non-zero on error * @param Flags Flags passed to the OpenFile function that created file_t * @return file descriptor, or -1 on error @@ -201,7 +201,7 @@ int FileToFd(file_t& F, std::error_code& EC, OpenFlags Flags); * Closes the file object. * * @param F On input, this is the file to close. On output, the file is - * set to WPI_kInvalidFile. + * set to WPI_INVALID_FILE. */ void CloseFile(file_t& F);