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

Unified Diff: base/platform_file_posix.cc

Issue 17779003: Port base/files/file_util_proxy to Native Client. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move NaCl workaround into platform_file_posix.cc. Created 7 years, 5 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
« base/files/file_util_proxy.cc ('K') | « base/platform_file.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/platform_file_posix.cc
diff --git a/base/platform_file_posix.cc b/base/platform_file_posix.cc
index 7e6335e88451a090c54a6370f75b5a0122a6b8b3..4d2012a67b5a3b8238d8845049b6effa73f8b99e 100644
--- a/base/platform_file_posix.cc
+++ b/base/platform_file_posix.cc
@@ -27,7 +27,9 @@ COMPILE_ASSERT(PLATFORM_FILE_FROM_BEGIN == SEEK_SET &&
PLATFORM_FILE_FROM_CURRENT == SEEK_CUR &&
PLATFORM_FILE_FROM_END == SEEK_END, whence_matches_system);
-#if defined(OS_BSD) || defined(OS_MACOSX)
+namespace {
+
+#if defined(OS_BSD) || defined(OS_MACOSX) || defined(OS_NACL)
typedef struct stat stat_wrapper_t;
static int CallFstat(int fd, stat_wrapper_t *sb) {
base::ThreadRestrictions::AssertIOAllowed();
@@ -41,6 +43,32 @@ static int CallFstat(int fd, stat_wrapper_t *sb) {
}
#endif
+// TODO(bbudge) Remove NaCl workarounds when it implements pread and pwrite.
+#if !defined(OS_NACL)
+static int CallPread(PlatformFile file, char* data, int size, int64 offset) {
+ return HANDLE_EINTR(pread(file, data, size, offset));
+}
+static int CallPwrite(PlatformFile file, const char* data, int size,
+ int64 offset) {
+ return HANDLE_EINTR(pwrite(file, data, size, offset));
+}
+#else
+static int CallPread(PlatformFile file, char* data, int size, int64 offset) {
+ lseek(file, static_cast<off_t>(offset), SEEK_SET);
+ return HANDLE_EINTR(read(file, data, size));
+}
+static int CallPwrite(PlatformFile file, const char* data, int size,
+ int64 offset) {
+ lseek(file, static_cast<off_t>(offset), SEEK_SET);
+ return HANDLE_EINTR(write(file, data, size));
+}
+#endif
+
+} // namespace
+
+// NaCl lacks many file handling system calls, so exclude any platform file
+// functions that can't be implemented there.
+#if !defined(OS_NACL)
// TODO(erikkay): does it make sense to support PLATFORM_FILE_EXCLUSIVE_* here?
PlatformFile CreatePlatformFileUnsafe(const FilePath& name,
int flags,
@@ -139,6 +167,7 @@ PlatformFile CreatePlatformFileUnsafe(const FilePath& name,
FILE* FdopenPlatformFile(PlatformFile file, const char* mode) {
return fdopen(file, mode);
}
+#endif // !defined(OS_NACL)
bool ClosePlatformFile(PlatformFile file) {
base::ThreadRestrictions::AssertIOAllowed();
@@ -163,8 +192,8 @@ int ReadPlatformFile(PlatformFile file, int64 offset, char* data, int size) {
int bytes_read = 0;
int rv;
do {
- rv = HANDLE_EINTR(pread(file, data + bytes_read,
- size - bytes_read, offset + bytes_read));
+ rv = CallPread(file, data + bytes_read,
+ size - bytes_read, offset + bytes_read);
if (rv <= 0)
break;
@@ -198,7 +227,7 @@ int ReadPlatformFileNoBestEffort(PlatformFile file, int64 offset,
if (file < 0)
return -1;
- return HANDLE_EINTR(pread(file, data, size, offset));
+ return CallPread(file, data, size, offset);
}
int ReadPlatformFileCurPosNoBestEffort(PlatformFile file,
@@ -214,8 +243,10 @@ int WritePlatformFile(PlatformFile file, int64 offset,
const char* data, int size) {
base::ThreadRestrictions::AssertIOAllowed();
+#if !defined(OS_NACL) // NaCl has no fcntl, but it shouldn't be needed here.
if (fcntl(file, F_GETFL) & O_APPEND)
return WritePlatformFileAtCurrentPos(file, data, size);
+#endif // !defined(OS_NACL)
if (file < 0 || size < 0)
return -1;
@@ -223,8 +254,8 @@ int WritePlatformFile(PlatformFile file, int64 offset,
int bytes_written = 0;
int rv;
do {
- rv = HANDLE_EINTR(pwrite(file, data + bytes_written,
- size - bytes_written, offset + bytes_written));
+ rv = CallPwrite(file, data + bytes_written,
+ size - bytes_written, offset + bytes_written);
if (rv <= 0)
break;
@@ -262,6 +293,7 @@ int WritePlatformFileCurPosNoBestEffort(PlatformFile file,
return HANDLE_EINTR(write(file, data, size));
}
+#if !defined(OS_NACL) // NaCl has no ftruncate or fsync.
bool TruncatePlatformFile(PlatformFile file, int64 length) {
base::ThreadRestrictions::AssertIOAllowed();
return ((file >= 0) && !HANDLE_EINTR(ftruncate(file, length)));
@@ -271,7 +303,9 @@ bool FlushPlatformFile(PlatformFile file) {
base::ThreadRestrictions::AssertIOAllowed();
return !HANDLE_EINTR(fsync(file));
}
+#endif // !defined(OS_NACL)
+#if !defined(OS_NACL)
bool TouchPlatformFile(PlatformFile file, const base::Time& last_access_time,
const base::Time& last_modified_time) {
base::ThreadRestrictions::AssertIOAllowed();
@@ -297,6 +331,7 @@ bool TouchPlatformFile(PlatformFile file, const base::Time& last_access_time,
return !futimes(file, times);
#endif
}
+#endif // !defined(OS_NACL)
bool GetPlatformFileInfo(PlatformFile file, PlatformFileInfo* info) {
if (!info)
@@ -322,8 +357,10 @@ PlatformFileError ErrnoToPlatformFileError(int saved_errno) {
case EROFS:
case EPERM:
return PLATFORM_FILE_ERROR_ACCESS_DENIED;
+#if !defined(OS_NACL) // ETXTBSY not defined by NaCl.
case ETXTBSY:
return PLATFORM_FILE_ERROR_IN_USE;
+#endif
case EEXIST:
return PLATFORM_FILE_ERROR_EXISTS;
case ENOENT:
« base/files/file_util_proxy.cc ('K') | « base/platform_file.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698