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

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: Fix weird Windows build error. Created 8 years, 7 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 }
84
81 COMPILE_ASSERT(O_RDONLY == 0, O_RDONLY_must_equal_zero); 85 COMPILE_ASSERT(O_RDONLY == 0, O_RDONLY_must_equal_zero);
82 86
83 int mode = S_IRUSR | S_IWUSR; 87 int mode = S_IRUSR | S_IWUSR;
84 #if defined(OS_CHROMEOS) 88 #if defined(OS_CHROMEOS)
85 mode |= S_IRGRP | S_IROTH; 89 mode |= S_IRGRP | S_IROTH;
86 #endif 90 #endif
87 91
88 int descriptor = 92 int descriptor =
89 HANDLE_EINTR(open(name.value().c_str(), open_flags, mode)); 93 HANDLE_EINTR(open(name.value().c_str(), open_flags, mode));
90 94
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 int ReadPlatformFile(PlatformFile file, int64 offset, char* data, int size) { 163 int ReadPlatformFile(PlatformFile file, int64 offset, char* data, int size) {
160 base::ThreadRestrictions::AssertIOAllowed(); 164 base::ThreadRestrictions::AssertIOAllowed();
161 if (file < 0 || size < 0) 165 if (file < 0 || size < 0)
162 return -1; 166 return -1;
163 167
164 int bytes_read = 0; 168 int bytes_read = 0;
165 int rv; 169 int rv;
166 do { 170 do {
167 rv = HANDLE_EINTR(pread(file, data + bytes_read, 171 rv = HANDLE_EINTR(pread(file, data + bytes_read,
168 size - bytes_read, offset + bytes_read)); 172 size - bytes_read, offset + bytes_read));
173 if (rv <= 0 && errno == ESPIPE) {
174 // The file descriptor represents a tty device. Try again without lseek.
175 rv = HANDLE_EINTR(read(file, data, size));
176 }
169 if (rv <= 0) 177 if (rv <= 0)
170 break; 178 break;
171 179
172 bytes_read += rv; 180 bytes_read += rv;
173 } while (bytes_read < size); 181 } while (bytes_read < size);
174 182
175 return bytes_read ? bytes_read : rv; 183 return bytes_read ? bytes_read : rv;
176 } 184 }
177 185
178 int ReadPlatformFileNoBestEffort(PlatformFile file, int64 offset, 186 int ReadPlatformFileNoBestEffort(PlatformFile file, int64 offset,
179 char* data, int size) { 187 char* data, int size) {
180 base::ThreadRestrictions::AssertIOAllowed(); 188 base::ThreadRestrictions::AssertIOAllowed();
181 if (file < 0) 189 if (file < 0)
182 return -1; 190 return -1;
183 191
184 return HANDLE_EINTR(pread(file, data, size, offset)); 192 return HANDLE_EINTR(pread(file, data, size, offset));
185 } 193 }
186 194
187 int WritePlatformFile(PlatformFile file, int64 offset, 195 int WritePlatformFile(PlatformFile file, int64 offset,
188 const char* data, int size) { 196 const char* data, int size) {
189 base::ThreadRestrictions::AssertIOAllowed(); 197 base::ThreadRestrictions::AssertIOAllowed();
190 if (file < 0 || size < 0) 198 if (file < 0 || size < 0)
191 return -1; 199 return -1;
192 200
193 int bytes_written = 0; 201 int bytes_written = 0;
194 int rv; 202 int rv;
195 do { 203 do {
196 rv = HANDLE_EINTR(pwrite(file, data + bytes_written, 204 rv = HANDLE_EINTR(pwrite(file, data + bytes_written,
197 size - bytes_written, offset + bytes_written)); 205 size - bytes_written, offset + bytes_written));
206 if (rv <= 0 && errno == ESPIPE) {
207 // The file descriptor represents a tty device. Try again without lseek.
208 rv = HANDLE_EINTR(write(file, data, size));
209 }
198 if (rv <= 0) 210 if (rv <= 0)
199 break; 211 break;
200 212
201 bytes_written += rv; 213 bytes_written += rv;
202 } while (bytes_written < size); 214 } while (bytes_written < size);
203 215
204 return bytes_written ? bytes_written : rv; 216 return bytes_written ? bytes_written : rv;
205 } 217 }
206 218
207 bool TruncatePlatformFile(PlatformFile file, int64 length) { 219 bool TruncatePlatformFile(PlatformFile file, int64 length) {
(...skipping 29 matching lines...) Expand all
237 info->is_directory = S_ISDIR(file_info.st_mode); 249 info->is_directory = S_ISDIR(file_info.st_mode);
238 info->is_symbolic_link = S_ISLNK(file_info.st_mode); 250 info->is_symbolic_link = S_ISLNK(file_info.st_mode);
239 info->size = file_info.st_size; 251 info->size = file_info.st_size;
240 info->last_modified = base::Time::FromTimeT(file_info.st_mtime); 252 info->last_modified = base::Time::FromTimeT(file_info.st_mtime);
241 info->last_accessed = base::Time::FromTimeT(file_info.st_atime); 253 info->last_accessed = base::Time::FromTimeT(file_info.st_atime);
242 info->creation_time = base::Time::FromTimeT(file_info.st_ctime); 254 info->creation_time = base::Time::FromTimeT(file_info.st_ctime);
243 return true; 255 return true;
244 } 256 }
245 257
246 } // namespace base 258 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698