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

Side by Side Diff: base/platform_file_win.cc

Issue 10392181: Implement serial API for Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: From -> At. Created 8 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/platform_file_posix.cc ('k') | chrome/browser/extensions/api/api_resource_controller.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/platform_file.h" 5 #include "base/platform_file.h"
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/threading/thread_restrictions.h" 9 #include "base/threading/thread_restrictions.h"
10 10
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 127
128 DWORD bytes_read; 128 DWORD bytes_read;
129 if (::ReadFile(file, data, size, &bytes_read, &overlapped) != 0) 129 if (::ReadFile(file, data, size, &bytes_read, &overlapped) != 0)
130 return bytes_read; 130 return bytes_read;
131 else if (ERROR_HANDLE_EOF == GetLastError()) 131 else if (ERROR_HANDLE_EOF == GetLastError())
132 return 0; 132 return 0;
133 133
134 return -1; 134 return -1;
135 } 135 }
136 136
137 int ReadPlatformFileNoBestEffort(PlatformFile file, int64 offset, 137 int ReadPlatformFileAtCurrentPos(PlatformFile file, char* data, int size) {
138 char* data, int size) { 138 return ReadPlatformFile(file, 0, data, size);
139 }
140
141 int ReadPlatformFileNoBestEffort(PlatformFile file, int64 offset, char* data,
142 int size) {
139 return ReadPlatformFile(file, offset, data, size); 143 return ReadPlatformFile(file, offset, data, size);
140 } 144 }
141 145
142 int WritePlatformFile(PlatformFile file, int64 offset, 146 int WritePlatformFile(PlatformFile file, int64 offset,
143 const char* data, int size) { 147 const char* data, int size) {
144 base::ThreadRestrictions::AssertIOAllowed(); 148 base::ThreadRestrictions::AssertIOAllowed();
145 if (file == kInvalidPlatformFileValue) 149 if (file == kInvalidPlatformFileValue)
146 return -1; 150 return -1;
147 151
148 LARGE_INTEGER offset_li; 152 LARGE_INTEGER offset_li;
149 offset_li.QuadPart = offset; 153 offset_li.QuadPart = offset;
150 154
151 OVERLAPPED overlapped = {0}; 155 OVERLAPPED overlapped = {0};
152 overlapped.Offset = offset_li.LowPart; 156 overlapped.Offset = offset_li.LowPart;
153 overlapped.OffsetHigh = offset_li.HighPart; 157 overlapped.OffsetHigh = offset_li.HighPart;
154 158
155 DWORD bytes_written; 159 DWORD bytes_written;
156 if (::WriteFile(file, data, size, &bytes_written, &overlapped) != 0) 160 if (::WriteFile(file, data, size, &bytes_written, &overlapped) != 0)
157 return bytes_written; 161 return bytes_written;
158 162
159 return -1; 163 return -1;
160 } 164 }
161 165
166 int WritePlatformFileAtCurrentPos(PlatformFile file, const char* data,
167 int size) {
168 return WritePlatformFile(file, 0, data, size);
169 }
170
162 bool TruncatePlatformFile(PlatformFile file, int64 length) { 171 bool TruncatePlatformFile(PlatformFile file, int64 length) {
163 base::ThreadRestrictions::AssertIOAllowed(); 172 base::ThreadRestrictions::AssertIOAllowed();
164 if (file == kInvalidPlatformFileValue) 173 if (file == kInvalidPlatformFileValue)
165 return false; 174 return false;
166 175
167 // Get the current file pointer. 176 // Get the current file pointer.
168 LARGE_INTEGER file_pointer; 177 LARGE_INTEGER file_pointer;
169 LARGE_INTEGER zero; 178 LARGE_INTEGER zero;
170 zero.QuadPart = 0; 179 zero.QuadPart = 0;
171 if (::SetFilePointerEx(file, zero, &file_pointer, FILE_CURRENT) == 0) 180 if (::SetFilePointerEx(file, zero, &file_pointer, FILE_CURRENT) == 0)
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 info->is_directory = 227 info->is_directory =
219 (file_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; 228 (file_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
220 info->is_symbolic_link = false; // Windows doesn't have symbolic links. 229 info->is_symbolic_link = false; // Windows doesn't have symbolic links.
221 info->last_modified = base::Time::FromFileTime(file_info.ftLastWriteTime); 230 info->last_modified = base::Time::FromFileTime(file_info.ftLastWriteTime);
222 info->last_accessed = base::Time::FromFileTime(file_info.ftLastAccessTime); 231 info->last_accessed = base::Time::FromFileTime(file_info.ftLastAccessTime);
223 info->creation_time = base::Time::FromFileTime(file_info.ftCreationTime); 232 info->creation_time = base::Time::FromFileTime(file_info.ftCreationTime);
224 return true; 233 return true;
225 } 234 }
226 235
227 } // namespace base 236 } // namespace base
OLDNEW
« no previous file with comments | « base/platform_file_posix.cc ('k') | chrome/browser/extensions/api/api_resource_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698