[PATCH] D46499: [Support] Add docs for 'openFileFor{Write,Read}'
Brian Gesiak via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu May 10 14:17:39 PDT 2018
modocache updated this revision to Diff 146224.
modocache edited the summary of this revision.
modocache added a comment.
I updated this diff to not only document how the ResultFD is set, but also make it a little more consistent across platforms. Previously Windows would only sometimes set it to -1 in the case of failure, now it always does.
Repository:
rL LLVM
https://reviews.llvm.org/D46499
Files:
include/llvm/Support/FileSystem.h
lib/Support/Windows/Path.inc
Index: lib/Support/Windows/Path.inc
===================================================================
--- lib/Support/Windows/Path.inc
+++ lib/Support/Windows/Path.inc
@@ -1052,6 +1052,7 @@
std::error_code openFileForRead(const Twine &Name, int &ResultFD,
SmallVectorImpl<char> *RealPath) {
+ ResultFD = -1;
SmallVector<wchar_t, 128> PathUTF16;
if (std::error_code EC = widenPath(Name, PathUTF16))
@@ -1074,17 +1075,16 @@
return EC;
}
- int FD = ::_open_osfhandle(intptr_t(H), 0);
- if (FD == -1) {
+ ResultFD = ::_open_osfhandle(intptr_t(H), 0);
+ if (ResultFD == -1) {
::CloseHandle(H);
return mapWindowsError(ERROR_INVALID_HANDLE);
}
// Fetch the real name of the file, if the user asked
if (RealPath)
realPathFromHandle(H, *RealPath);
- ResultFD = FD;
return std::error_code();
}
@@ -1094,6 +1094,7 @@
assert((!(Flags & sys::fs::F_Excl) || !(Flags & sys::fs::F_Append)) &&
"Cannot specify both 'excl' and 'append' file creation flags!");
+ ResultFD = -1;
SmallVector<wchar_t, 128> PathUTF16;
if (std::error_code EC = widenPath(Name, PathUTF16))
@@ -1141,13 +1142,12 @@
if (Flags & F_Text)
OpenFlags |= _O_TEXT;
- int FD = ::_open_osfhandle(intptr_t(H), OpenFlags);
- if (FD == -1) {
+ ResultFD = ::_open_osfhandle(intptr_t(H), OpenFlags);
+ if (ResultFD == -1) {
::CloseHandle(H);
return mapWindowsError(ERROR_INVALID_HANDLE);
}
- ResultFD = FD;
return std::error_code();
}
Index: include/llvm/Support/FileSystem.h
===================================================================
--- include/llvm/Support/FileSystem.h
+++ include/llvm/Support/FileSystem.h
@@ -817,9 +817,38 @@
return A;
}
+/// @brief Opens the file with the given name in a write-only or read-write
+/// mode, returning its open file descriptor. If the file does not exist, it
+/// is created.
+///
+/// The caller is responsible for closing the file descriptor once they are
+/// finished with it.
+///
+/// @param Name The path of the file to open, relative or absolute.
+/// @param ResultFD If the file could be opened successfully, its descriptor
+/// is stored in this location. Otherwise, this is set to -1.
+/// @param Flags Additional flags used to determine whether the file should be
+/// opened in, for example, read-write or in write-only mode.
+/// @param Mode The access permissions of the file, represented in octal.
+/// @returns errc::success if \a Name has been opened, otherwise a
+/// platform-specific error_code.
std::error_code openFileForWrite(const Twine &Name, int &ResultFD,
OpenFlags Flags, unsigned Mode = 0666);
+/// @brief Opens the file with the given name in a read-only mode, returning
+/// its open file descriptor.
+///
+/// The caller is responsible for closing the file descriptor once they are
+/// finished with it.
+///
+/// @param Name The path of the file to open, relative or absolute.
+/// @param ResultFD If the file could be opened successfully, its descriptor
+/// is stored in this location. Otherwise, this is set to -1.
+/// @param RealPath If nonnull, extra work is done to determine the real path
+/// of the opened file, and that path is stored in this
+/// location.
+/// @returns errc::success if \a Name has been opened, otherwise a
+/// platform-specific error_code.
std::error_code openFileForRead(const Twine &Name, int &ResultFD,
SmallVectorImpl<char> *RealPath = nullptr);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46499.146224.patch
Type: text/x-patch
Size: 3639 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180510/88dc7cf2/attachment.bin>
More information about the llvm-commits
mailing list