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

Side by Side Diff: base/platform_file_posix.cc

Issue 8843: Add write and read/write support to FileStream (renamed from FileInputStream)... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 1 month 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.h ('k') | base/platform_file_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:mergeinfo
Merged /branches/chrome_webkit_merge_branch/net/disk_cache/os_file_posix.cc:r69-2775
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "net/disk_cache/os_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 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 12
13 namespace disk_cache { 13 namespace base {
14 14
15 OSFile CreateOSFile(const std::wstring& name, int flags, bool* created) { 15 // TODO(erikkay): does it make sense to support PLATFORM_FILE_EXCLUSIVE_* here?
16 PlatformFile CreatePlatformFile(const std::wstring& name,
17 int flags,
18 bool* created) {
16 int open_flags = 0; 19 int open_flags = 0;
17 if (flags & OS_FILE_CREATE) 20 if (flags & PLATFORM_FILE_CREATE)
18 open_flags = O_CREAT | O_EXCL; 21 open_flags = O_CREAT | O_EXCL;
19 22
20 if (flags & OS_FILE_CREATE_ALWAYS) { 23 if (flags & PLATFORM_FILE_CREATE_ALWAYS) {
21 DCHECK(!open_flags); 24 DCHECK(!open_flags);
22 open_flags = O_CREAT | O_TRUNC; 25 open_flags = O_CREAT | O_TRUNC;
23 } 26 }
24 27
25 if (!open_flags && !(flags & OS_FILE_OPEN) && 28 if (!open_flags && !(flags & PLATFORM_FILE_OPEN) &&
26 !(flags & OS_FILE_OPEN_ALWAYS)) { 29 !(flags & PLATFORM_FILE_OPEN_ALWAYS)) {
27 NOTREACHED(); 30 NOTREACHED();
28 errno = ENOTSUP; 31 errno = ENOTSUP;
29 return INVALID_HANDLE_VALUE; 32 return INVALID_HANDLE_VALUE;
30 } 33 }
31 34
32 if (flags & OS_FILE_WRITE && flags & OS_FILE_READ) { 35 if (flags & PLATFORM_FILE_WRITE && flags & PLATFORM_FILE_READ) {
33 open_flags |= O_RDWR; 36 open_flags |= O_RDWR;
34 } else if (flags & OS_FILE_WRITE) { 37 } else if (flags & PLATFORM_FILE_WRITE) {
35 open_flags |= O_WRONLY; 38 open_flags |= O_WRONLY;
36 } else if (!(flags & OS_FILE_READ)) { 39 } else if (!(flags & PLATFORM_FILE_READ)) {
37 NOTREACHED(); 40 NOTREACHED();
38 } 41 }
39 42
40 DCHECK(O_RDONLY == 0); 43 DCHECK(O_RDONLY == 0);
41 44
42 int descriptor = open(WideToUTF8(name).c_str(), open_flags, 45 int descriptor = open(WideToUTF8(name).c_str(), open_flags,
43 S_IRUSR | S_IWUSR); 46 S_IRUSR | S_IWUSR);
44 47
45 if (flags & OS_FILE_OPEN_ALWAYS) { 48 if (flags & PLATFORM_FILE_OPEN_ALWAYS) {
46 if (descriptor > 0) { 49 if (descriptor > 0) {
47 if (created) 50 if (created)
48 *created = false; 51 *created = false;
49 } else { 52 } else {
50 open_flags |= O_CREAT; 53 open_flags |= O_CREAT;
51 descriptor = open(WideToUTF8(name).c_str(), open_flags, 54 descriptor = open(WideToUTF8(name).c_str(), open_flags,
52 S_IRUSR | S_IWUSR); 55 S_IRUSR | S_IWUSR);
53 if (created && descriptor > 0) 56 if (created && descriptor > 0)
54 *created = true; 57 *created = true;
55 } 58 }
56 } 59 }
57 60
58 return descriptor; 61 return descriptor;
59 } 62 }
60 63
61 } // namespace disk_cache 64 } // namespace base
OLDNEW
« no previous file with comments | « 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