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

Side by Side Diff: base/platform_file_posix.cc

Issue 10392181: Implement serial API for Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: TerminalDevice -> FromCurrentPos 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
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/platform_file.h" 5 #include "base/platform_file.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <sys/stat.h> 9 #include <sys/stat.h>
10 #include <unistd.h> 10 #include <unistd.h>
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 if (flags & PLATFORM_FILE_WRITE && flags & PLATFORM_FILE_READ) { 71 if (flags & PLATFORM_FILE_WRITE && flags & PLATFORM_FILE_READ) {
72 open_flags |= O_RDWR; 72 open_flags |= O_RDWR;
73 } else if (flags & PLATFORM_FILE_WRITE) { 73 } else if (flags & PLATFORM_FILE_WRITE) {
74 open_flags |= O_WRONLY; 74 open_flags |= O_WRONLY;
75 } else if (!(flags & PLATFORM_FILE_READ) && 75 } else if (!(flags & PLATFORM_FILE_READ) &&
76 !(flags & PLATFORM_FILE_WRITE_ATTRIBUTES) && 76 !(flags & PLATFORM_FILE_WRITE_ATTRIBUTES) &&
77 !(flags & PLATFORM_FILE_OPEN_ALWAYS)) { 77 !(flags & PLATFORM_FILE_OPEN_ALWAYS)) {
78 NOTREACHED(); 78 NOTREACHED();
79 } 79 }
80 80
81 if (flags & PLATFORM_FILE_TERMINAL_DEVICE)
82 open_flags |= O_NOCTTY | O_NDELAY;
83
81 COMPILE_ASSERT(O_RDONLY == 0, O_RDONLY_must_equal_zero); 84 COMPILE_ASSERT(O_RDONLY == 0, O_RDONLY_must_equal_zero);
82 85
83 int mode = S_IRUSR | S_IWUSR; 86 int mode = S_IRUSR | S_IWUSR;
84 #if defined(OS_CHROMEOS) 87 #if defined(OS_CHROMEOS)
85 mode |= S_IRGRP | S_IROTH; 88 mode |= S_IRGRP | S_IROTH;
86 #endif 89 #endif
87 90
88 int descriptor = 91 int descriptor =
89 HANDLE_EINTR(open(name.value().c_str(), open_flags, mode)); 92 HANDLE_EINTR(open(name.value().c_str(), open_flags, mode));
90 93
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 size - bytes_read, offset + bytes_read)); 171 size - bytes_read, offset + bytes_read));
169 if (rv <= 0) 172 if (rv <= 0)
170 break; 173 break;
171 174
172 bytes_read += rv; 175 bytes_read += rv;
173 } while (bytes_read < size); 176 } while (bytes_read < size);
174 177
175 return bytes_read ? bytes_read : rv; 178 return bytes_read ? bytes_read : rv;
176 } 179 }
177 180
181 int ReadPlatformFileFromCurrentPos(PlatformFile file, char* data, int size) {
182 base::ThreadRestrictions::AssertIOAllowed();
183 if (file < 0 || size < 0)
184 return -1;
185
186 int bytes_read = 0;
187 int rv;
188 do {
189 rv = HANDLE_EINTR(read(file, data, size));
190 if (rv <= 0)
191 break;
192
193 bytes_read += rv;
194 } while (bytes_read < size);
195
196 return bytes_read ? bytes_read : rv;
197 }
198
178 int ReadPlatformFileNoBestEffort(PlatformFile file, int64 offset, 199 int ReadPlatformFileNoBestEffort(PlatformFile file, int64 offset,
179 char* data, int size) { 200 char* data, int size) {
180 base::ThreadRestrictions::AssertIOAllowed(); 201 base::ThreadRestrictions::AssertIOAllowed();
181 if (file < 0) 202 if (file < 0)
182 return -1; 203 return -1;
183 204
184 return HANDLE_EINTR(pread(file, data, size, offset)); 205 return HANDLE_EINTR(pread(file, data, size, offset));
185 } 206 }
186 207
187 int WritePlatformFile(PlatformFile file, int64 offset, 208 int WritePlatformFile(PlatformFile file, int64 offset,
188 const char* data, int size) { 209 const char* data, int size) {
189 base::ThreadRestrictions::AssertIOAllowed(); 210 base::ThreadRestrictions::AssertIOAllowed();
190 if (file < 0 || size < 0) 211 if (file < 0 || size < 0)
191 return -1; 212 return -1;
192 213
193 int bytes_written = 0; 214 int bytes_written = 0;
194 int rv; 215 int rv;
195 do { 216 do {
196 rv = HANDLE_EINTR(pwrite(file, data + bytes_written, 217 rv = HANDLE_EINTR(pwrite(file, data + bytes_written,
197 size - bytes_written, offset + bytes_written)); 218 size - bytes_written, offset + bytes_written));
198 if (rv <= 0) 219 if (rv <= 0)
199 break; 220 break;
200 221
201 bytes_written += rv; 222 bytes_written += rv;
202 } while (bytes_written < size); 223 } while (bytes_written < size);
203 224
204 return bytes_written ? bytes_written : rv; 225 return bytes_written ? bytes_written : rv;
205 } 226 }
206 227
228 int WritePlatformFileFromCurrentPos(PlatformFile file,
229 const char* data, int size) {
230 base::ThreadRestrictions::AssertIOAllowed();
231 if (file < 0 || size < 0)
232 return -1;
233
234 int bytes_written = 0;
235 int rv;
236 do {
237 rv = HANDLE_EINTR(write(file, data, size));
238 if (rv <= 0)
239 break;
240
241 bytes_written += rv;
242 } while (bytes_written < size);
243
244 return bytes_written ? bytes_written : rv;
245 }
246
207 bool TruncatePlatformFile(PlatformFile file, int64 length) { 247 bool TruncatePlatformFile(PlatformFile file, int64 length) {
208 base::ThreadRestrictions::AssertIOAllowed(); 248 base::ThreadRestrictions::AssertIOAllowed();
209 return ((file >= 0) && !HANDLE_EINTR(ftruncate(file, length))); 249 return ((file >= 0) && !HANDLE_EINTR(ftruncate(file, length)));
210 } 250 }
211 251
212 bool FlushPlatformFile(PlatformFile file) { 252 bool FlushPlatformFile(PlatformFile file) {
213 base::ThreadRestrictions::AssertIOAllowed(); 253 base::ThreadRestrictions::AssertIOAllowed();
214 return !HANDLE_EINTR(fsync(file)); 254 return !HANDLE_EINTR(fsync(file));
215 } 255 }
216 256
(...skipping 20 matching lines...) Expand all
237 info->is_directory = S_ISDIR(file_info.st_mode); 277 info->is_directory = S_ISDIR(file_info.st_mode);
238 info->is_symbolic_link = S_ISLNK(file_info.st_mode); 278 info->is_symbolic_link = S_ISLNK(file_info.st_mode);
239 info->size = file_info.st_size; 279 info->size = file_info.st_size;
240 info->last_modified = base::Time::FromTimeT(file_info.st_mtime); 280 info->last_modified = base::Time::FromTimeT(file_info.st_mtime);
241 info->last_accessed = base::Time::FromTimeT(file_info.st_atime); 281 info->last_accessed = base::Time::FromTimeT(file_info.st_atime);
242 info->creation_time = base::Time::FromTimeT(file_info.st_ctime); 282 info->creation_time = base::Time::FromTimeT(file_info.st_ctime);
243 return true; 283 return true;
244 } 284 }
245 285
246 } // namespace base 286 } // namespace base
OLDNEW
« base/platform_file.h ('K') | « base/platform_file.h ('k') | base/platform_file_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698