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

Side by Side Diff: base/files/file_win.cc

Issue 1549853002: Switch to standard integer types in base/files/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 4 years, 12 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
« no previous file with comments | « base/files/file_util_win.cc ('k') | base/files/important_file_writer.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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/files/file.h" 5 #include "base/files/file.h"
6 6
7 #include <io.h> 7 #include <io.h>
8 #include <stdint.h>
8 9
9 #include "base/logging.h" 10 #include "base/logging.h"
10 #include "base/metrics/sparse_histogram.h" 11 #include "base/metrics/sparse_histogram.h"
11 #include "base/threading/thread_restrictions.h" 12 #include "base/threading/thread_restrictions.h"
12 13
13 namespace base { 14 namespace base {
14 15
15 // Make sure our Whence mappings match the system headers. 16 // Make sure our Whence mappings match the system headers.
16 static_assert(File::FROM_BEGIN == FILE_BEGIN && 17 static_assert(File::FROM_BEGIN == FILE_BEGIN &&
17 File::FROM_CURRENT == FILE_CURRENT && 18 File::FROM_CURRENT == FILE_CURRENT &&
(...skipping 14 matching lines...) Expand all
32 33
33 void File::Close() { 34 void File::Close() {
34 if (!file_.IsValid()) 35 if (!file_.IsValid())
35 return; 36 return;
36 37
37 ThreadRestrictions::AssertIOAllowed(); 38 ThreadRestrictions::AssertIOAllowed();
38 SCOPED_FILE_TRACE("Close"); 39 SCOPED_FILE_TRACE("Close");
39 file_.Close(); 40 file_.Close();
40 } 41 }
41 42
42 int64 File::Seek(Whence whence, int64 offset) { 43 int64_t File::Seek(Whence whence, int64_t offset) {
43 ThreadRestrictions::AssertIOAllowed(); 44 ThreadRestrictions::AssertIOAllowed();
44 DCHECK(IsValid()); 45 DCHECK(IsValid());
45 46
46 SCOPED_FILE_TRACE_WITH_SIZE("Seek", offset); 47 SCOPED_FILE_TRACE_WITH_SIZE("Seek", offset);
47 48
48 LARGE_INTEGER distance, res; 49 LARGE_INTEGER distance, res;
49 distance.QuadPart = offset; 50 distance.QuadPart = offset;
50 DWORD move_method = static_cast<DWORD>(whence); 51 DWORD move_method = static_cast<DWORD>(whence);
51 if (!SetFilePointerEx(file_.Get(), distance, &res, move_method)) 52 if (!SetFilePointerEx(file_.Get(), distance, &res, move_method))
52 return -1; 53 return -1;
53 return res.QuadPart; 54 return res.QuadPart;
54 } 55 }
55 56
56 int File::Read(int64 offset, char* data, int size) { 57 int File::Read(int64_t offset, char* data, int size) {
57 ThreadRestrictions::AssertIOAllowed(); 58 ThreadRestrictions::AssertIOAllowed();
58 DCHECK(IsValid()); 59 DCHECK(IsValid());
59 DCHECK(!async_); 60 DCHECK(!async_);
60 if (size < 0) 61 if (size < 0)
61 return -1; 62 return -1;
62 63
63 SCOPED_FILE_TRACE_WITH_SIZE("Read", size); 64 SCOPED_FILE_TRACE_WITH_SIZE("Read", size);
64 65
65 LARGE_INTEGER offset_li; 66 LARGE_INTEGER offset_li;
66 offset_li.QuadPart = offset; 67 offset_li.QuadPart = offset;
(...skipping 22 matching lines...) Expand all
89 90
90 DWORD bytes_read; 91 DWORD bytes_read;
91 if (::ReadFile(file_.Get(), data, size, &bytes_read, NULL)) 92 if (::ReadFile(file_.Get(), data, size, &bytes_read, NULL))
92 return bytes_read; 93 return bytes_read;
93 if (ERROR_HANDLE_EOF == GetLastError()) 94 if (ERROR_HANDLE_EOF == GetLastError())
94 return 0; 95 return 0;
95 96
96 return -1; 97 return -1;
97 } 98 }
98 99
99 int File::ReadNoBestEffort(int64 offset, char* data, int size) { 100 int File::ReadNoBestEffort(int64_t offset, char* data, int size) {
100 // TODO(dbeam): trace this separately? 101 // TODO(dbeam): trace this separately?
101 return Read(offset, data, size); 102 return Read(offset, data, size);
102 } 103 }
103 104
104 int File::ReadAtCurrentPosNoBestEffort(char* data, int size) { 105 int File::ReadAtCurrentPosNoBestEffort(char* data, int size) {
105 // TODO(dbeam): trace this separately? 106 // TODO(dbeam): trace this separately?
106 return ReadAtCurrentPos(data, size); 107 return ReadAtCurrentPos(data, size);
107 } 108 }
108 109
109 int File::Write(int64 offset, const char* data, int size) { 110 int File::Write(int64_t offset, const char* data, int size) {
110 ThreadRestrictions::AssertIOAllowed(); 111 ThreadRestrictions::AssertIOAllowed();
111 DCHECK(IsValid()); 112 DCHECK(IsValid());
112 DCHECK(!async_); 113 DCHECK(!async_);
113 114
114 SCOPED_FILE_TRACE_WITH_SIZE("Write", size); 115 SCOPED_FILE_TRACE_WITH_SIZE("Write", size);
115 116
116 LARGE_INTEGER offset_li; 117 LARGE_INTEGER offset_li;
117 offset_li.QuadPart = offset; 118 offset_li.QuadPart = offset;
118 119
119 OVERLAPPED overlapped = {0}; 120 OVERLAPPED overlapped = {0};
(...skipping 20 matching lines...) Expand all
140 if (::WriteFile(file_.Get(), data, size, &bytes_written, NULL)) 141 if (::WriteFile(file_.Get(), data, size, &bytes_written, NULL))
141 return bytes_written; 142 return bytes_written;
142 143
143 return -1; 144 return -1;
144 } 145 }
145 146
146 int File::WriteAtCurrentPosNoBestEffort(const char* data, int size) { 147 int File::WriteAtCurrentPosNoBestEffort(const char* data, int size) {
147 return WriteAtCurrentPos(data, size); 148 return WriteAtCurrentPos(data, size);
148 } 149 }
149 150
150 int64 File::GetLength() { 151 int64_t File::GetLength() {
151 ThreadRestrictions::AssertIOAllowed(); 152 ThreadRestrictions::AssertIOAllowed();
152 DCHECK(IsValid()); 153 DCHECK(IsValid());
153 154
154 SCOPED_FILE_TRACE("GetLength"); 155 SCOPED_FILE_TRACE("GetLength");
155 156
156 LARGE_INTEGER size; 157 LARGE_INTEGER size;
157 if (!::GetFileSizeEx(file_.Get(), &size)) 158 if (!::GetFileSizeEx(file_.Get(), &size))
158 return -1; 159 return -1;
159 160
160 return static_cast<int64>(size.QuadPart); 161 return static_cast<int64_t>(size.QuadPart);
161 } 162 }
162 163
163 bool File::SetLength(int64 length) { 164 bool File::SetLength(int64_t length) {
164 ThreadRestrictions::AssertIOAllowed(); 165 ThreadRestrictions::AssertIOAllowed();
165 DCHECK(IsValid()); 166 DCHECK(IsValid());
166 167
167 SCOPED_FILE_TRACE_WITH_SIZE("SetLength", length); 168 SCOPED_FILE_TRACE_WITH_SIZE("SetLength", length);
168 169
169 // Get the current file pointer. 170 // Get the current file pointer.
170 LARGE_INTEGER file_pointer; 171 LARGE_INTEGER file_pointer;
171 LARGE_INTEGER zero; 172 LARGE_INTEGER zero;
172 zero.QuadPart = 0; 173 zero.QuadPart = 0;
173 if (!::SetFilePointerEx(file_.Get(), zero, &file_pointer, FILE_CURRENT)) 174 if (!::SetFilePointerEx(file_.Get(), zero, &file_pointer, FILE_CURRENT))
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 case ERROR_FILE_CORRUPT: 303 case ERROR_FILE_CORRUPT:
303 case ERROR_DISK_CORRUPT: 304 case ERROR_DISK_CORRUPT:
304 return FILE_ERROR_IO; 305 return FILE_ERROR_IO;
305 default: 306 default:
306 UMA_HISTOGRAM_SPARSE_SLOWLY("PlatformFile.UnknownErrors.Windows", 307 UMA_HISTOGRAM_SPARSE_SLOWLY("PlatformFile.UnknownErrors.Windows",
307 last_error); 308 last_error);
308 return FILE_ERROR_FAILED; 309 return FILE_ERROR_FAILED;
309 } 310 }
310 } 311 }
311 312
312 void File::DoInitialize(const FilePath& path, uint32 flags) { 313 void File::DoInitialize(const FilePath& path, uint32_t flags) {
313 ThreadRestrictions::AssertIOAllowed(); 314 ThreadRestrictions::AssertIOAllowed();
314 DCHECK(!IsValid()); 315 DCHECK(!IsValid());
315 316
316 DWORD disposition = 0; 317 DWORD disposition = 0;
317 318
318 if (flags & FLAG_OPEN) 319 if (flags & FLAG_OPEN)
319 disposition = OPEN_EXISTING; 320 disposition = OPEN_EXISTING;
320 321
321 if (flags & FLAG_CREATE) { 322 if (flags & FLAG_CREATE) {
322 DCHECK(!disposition); 323 DCHECK(!disposition);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 ThreadRestrictions::AssertIOAllowed(); 400 ThreadRestrictions::AssertIOAllowed();
400 DCHECK(IsValid()); 401 DCHECK(IsValid());
401 return ::FlushFileBuffers(file_.Get()) != FALSE; 402 return ::FlushFileBuffers(file_.Get()) != FALSE;
402 } 403 }
403 404
404 void File::SetPlatformFile(PlatformFile file) { 405 void File::SetPlatformFile(PlatformFile file) {
405 file_.Set(file); 406 file_.Set(file);
406 } 407 }
407 408
408 } // namespace base 409 } // namespace base
OLDNEW
« no previous file with comments | « base/files/file_util_win.cc ('k') | base/files/important_file_writer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698