Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2807)

Unified Diff: base/file_util_posix.cc

Issue 100225: POSIX: Add a macro for handling EINTR. (Closed)
Patch Set: ... Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/file_util_linux.cc ('k') | base/message_pump_glib.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/file_util_posix.cc
diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc
index 1835d3ada45d97800081c644cdc8d3336c9a7277..2a0cfe9ea8daf7f09020ae96d3f174c9561523f8 100644
--- a/base/file_util_posix.cc
+++ b/base/file_util_posix.cc
@@ -22,6 +22,7 @@
#include <fstream>
#include "base/basictypes.h"
+#include "base/eintr_wrappers.h"
#include "base/file_path.h"
#include "base/logging.h"
#include "base/string_util.h"
@@ -335,11 +336,11 @@ bool GetFileCreationLocalTime(const std::string& filename,
bool ReadFromFD(int fd, char* buffer, size_t bytes) {
size_t total_read = 0;
while (total_read < bytes) {
- ssize_t bytes_read = read(fd, buffer + total_read, bytes - total_read);
- if (bytes_read > 0)
- total_read += bytes_read;
- else if (bytes_read == 0 || errno != EINTR)
+ ssize_t bytes_read =
+ HANDLE_EINTR(read(fd, buffer + total_read, bytes - total_read));
+ if (bytes_read <= 0)
break;
+ total_read += bytes_read;
}
return total_read == bytes;
}
@@ -453,8 +454,8 @@ int ReadFile(const FilePath& filename, char* data, int size) {
if (fd < 0)
return -1;
- int ret_value = read(fd, data, size);
- close(fd);
+ int ret_value = HANDLE_EINTR(read(fd, data, size));
+ HANDLE_EINTR(close(fd));
return ret_value;
}
@@ -466,17 +467,17 @@ int WriteFile(const FilePath& filename, const char* data, int size) {
// Allow for partial writes
ssize_t bytes_written_total = 0;
do {
- ssize_t bytes_written_partial = write(fd,
- data + bytes_written_total,
- size - bytes_written_total);
+ ssize_t bytes_written_partial =
+ HANDLE_EINTR(write(fd, data + bytes_written_total,
+ size - bytes_written_total));
if (bytes_written_partial < 0) {
- close(fd);
+ HANDLE_EINTR(close(fd));
return -1;
}
bytes_written_total += bytes_written_partial;
} while (bytes_written_total < size);
- close(fd);
+ HANDLE_EINTR(close(fd));
return bytes_written_total;
}
« no previous file with comments | « base/file_util_linux.cc ('k') | base/message_pump_glib.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698