[wpiutil] Rename WPI_kInvalidFile to WPI_INVALID_FILE

This commit is contained in:
Peter Johnson
2026-03-16 23:55:14 -07:00
parent 4059797635
commit c5e32652f9
3 changed files with 25 additions and 25 deletions

View File

@@ -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

View File

@@ -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);