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

Side by Side Diff: net/disk_cache/os_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 | « net/disk_cache/os_file.h ('k') | net/disk_cache/os_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')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "net/disk_cache/os_file.h"
6
7 #include <fcntl.h>
8 #include <errno.h>
9
10 #include "base/logging.h"
11 #include "base/string_util.h"
12
13 namespace disk_cache {
14
15 OSFile CreateOSFile(const std::wstring& name, int flags, bool* created) {
16 int open_flags = 0;
17 if (flags & OS_FILE_CREATE)
18 open_flags = O_CREAT | O_EXCL;
19
20 if (flags & OS_FILE_CREATE_ALWAYS) {
21 DCHECK(!open_flags);
22 open_flags = O_CREAT | O_TRUNC;
23 }
24
25 if (!open_flags && !(flags & OS_FILE_OPEN) &&
26 !(flags & OS_FILE_OPEN_ALWAYS)) {
27 NOTREACHED();
28 errno = ENOTSUP;
29 return INVALID_HANDLE_VALUE;
30 }
31
32 if (flags & OS_FILE_WRITE && flags & OS_FILE_READ) {
33 open_flags |= O_RDWR;
34 } else if (flags & OS_FILE_WRITE) {
35 open_flags |= O_WRONLY;
36 } else if (!(flags & OS_FILE_READ)) {
37 NOTREACHED();
38 }
39
40 DCHECK(O_RDONLY == 0);
41
42 int descriptor = open(WideToUTF8(name).c_str(), open_flags,
43 S_IRUSR | S_IWUSR);
44
45 if (flags & OS_FILE_OPEN_ALWAYS) {
46 if (descriptor > 0) {
47 if (created)
48 *created = false;
49 } else {
50 open_flags |= O_CREAT;
51 descriptor = open(WideToUTF8(name).c_str(), open_flags,
52 S_IRUSR | S_IWUSR);
53 if (created && descriptor > 0)
54 *created = true;
55 }
56 }
57
58 return descriptor;
59 }
60
61 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/os_file.h ('k') | net/disk_cache/os_file_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698