mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[wpiutil] Rename WPI_kInvalidFile to WPI_INVALID_FILE
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<fs::file_t>(-1)
|
||||
#define WPI_INVALID_FILE reinterpret_cast<fs::file_t>(-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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user