summaryrefslogtreecommitdiffstats
path: root/chromium/base/files/file_util.h
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2024-02-22 13:19:49 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2024-03-12 13:45:06 +0000
commit9c1f44f67466fea2fb20bb6f31fea388d8c65961 (patch)
tree03e7709aa7ed9a7cf2ec26ca410acd0b4c536666 /chromium/base/files/file_util.h
parentada9ddbf8c604585ac344b72f7bb63ac27c84726 (diff)
BASELINE: Update Chromium to 122.0.6261.72
Change-Id: I655fa6da670f5e82a4c0df33630e388663de2a8e Reviewed-on: https://codereview.qt-project.org/c/qt/qtwebengine-chromium/+/542310 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/base/files/file_util.h')
-rw-r--r--chromium/base/files/file_util.h27
1 files changed, 22 insertions, 5 deletions
diff --git a/chromium/base/files/file_util.h b/chromium/base/files/file_util.h
index 03185281012..19c7c42225e 100644
--- a/chromium/base/files/file_util.h
+++ b/chromium/base/files/file_util.h
@@ -13,6 +13,7 @@
#include <stdio.h>
#include <limits>
+#include <optional>
#include <set>
#include <string>
@@ -264,9 +265,11 @@ BASE_EXPORT bool ReadStreamToStringWithMaxSize(FILE* stream,
#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
-// Read exactly |bytes| bytes from file descriptor |fd|, storing the result
-// in |buffer|. This function is protected against EINTR and partial reads.
-// Returns true iff |bytes| bytes have been successfully read from |fd|.
+// Reads exactly as many bytes as `buffer` can hold from file descriptor `fd`
+// into `buffer`. This function is protected against EINTR and partial reads.
+// Returns true iff `buffer` was successfully filled with bytes read from `fd`.
+BASE_EXPORT bool ReadFromFD(int fd, span<char> buffer);
+// TODO(https://crbug.com/1490484): Migrate callers to the span variant.
BASE_EXPORT bool ReadFromFD(int fd, char* buffer, size_t bytes);
// Performs the same function as CreateAndOpenTemporaryStreamInDir(), but
@@ -527,14 +530,23 @@ BASE_EXPORT File FILEToFile(FILE* file_stream);
// This is a cross-platform analog to Windows' SetEndOfFile() function.
BASE_EXPORT bool TruncateFile(FILE* file);
-// Reads at most the given number of bytes from the file into the buffer.
-// Returns the number of read bytes, or -1 on error.
+// Reads from the file into `buffer`. This will read at most as many bytes as
+// `buffer` can hold, but may not always fill `buffer` entirely.
+// Returns the number of bytes read, or nullopt on error.
+// TODO(crbug.com/1333521): Despite the 64-bit return value, this only supports
+// reading at most INT_MAX bytes. The program will crash if a buffer is passed
+// whose length exceeds INT_MAX.
+BASE_EXPORT std::optional<uint64_t> ReadFile(const FilePath& filename,
+ span<char> buffer);
+// Same as above, but returns -1 on error.
+// TODO(https://crbug.com/1490484): Migrate callers to the span variant.
BASE_EXPORT int ReadFile(const FilePath& filename, char* data, int max_size);
// Writes the given buffer into the file, overwriting any data that was
// previously there. Returns the number of bytes written, or -1 on error.
// If file doesn't exist, it gets created with read/write permissions for all.
// Note that the other variants of WriteFile() below may be easier to use.
+// TODO(https://crbug.com/1490484): Migrate callers to the span variant.
BASE_EXPORT int WriteFile(const FilePath& filename, const char* data,
int size);
@@ -646,6 +658,11 @@ BASE_EXPORT bool CreateLocalNonBlockingPipe(int fds[2]);
// Returns true if it was able to set it in the close-on-exec mode, otherwise
// false.
BASE_EXPORT bool SetCloseOnExec(int fd);
+
+// Removes close-on-exec flag from the given |fd|.
+// Returns true if it was able to remove the close-on-exec flag, otherwise
+// false.
+BASE_EXPORT bool RemoveCloseOnExec(int fd);
#endif // BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#if BUILDFLAG(IS_MAC)