blob: 508103ac7d4e1ebac1d376565bd25f3b86abe258 [file] [log] [blame]
rvargas@google.comb1ae3192013-11-28 10:31:31 +09001// Copyright (c) 2011 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
rvargas@chromium.org12938d72013-12-04 09:46:32 +09005#include "base/files/file.h"
6
7// TODO(rvargas): remove this (needed for kInvalidPlatformFileValue).
rvargas@google.comb1ae3192013-11-28 10:31:31 +09008#include "base/platform_file.h"
9
10namespace base {
11
rvargas@chromium.org12938d72013-12-04 09:46:32 +090012File::Info::Info()
rvargas@google.comb1ae3192013-11-28 10:31:31 +090013 : size(0),
14 is_directory(false),
15 is_symbolic_link(false) {
16}
17
rvargas@chromium.org12938d72013-12-04 09:46:32 +090018File::Info::~Info() {
19}
20
21File::File()
22 : file_(kInvalidPlatformFileValue),
23 error_(FILE_OK),
24 created_(false),
25 async_(false) {
26}
rvargas@google.comb1ae3192013-11-28 10:31:31 +090027
28#if !defined(OS_NACL)
rvargas@chromium.org12938d72013-12-04 09:46:32 +090029File::File(const FilePath& name, uint32 flags)
30 : file_(kInvalidPlatformFileValue),
31 error_(FILE_OK),
32 created_(false),
33 async_(false) {
rvargas@chromium.orge207eae2014-01-04 07:14:15 +090034 Initialize(name, flags);
rvargas@google.comb1ae3192013-11-28 10:31:31 +090035}
36#endif
37
rvargas@chromium.orge207eae2014-01-04 07:14:15 +090038File::File(PlatformFile platform_file)
39 : file_(platform_file),
40 error_(FILE_OK),
41 created_(false),
42 async_(false) {
43}
44
rvargas@chromium.org12938d72013-12-04 09:46:32 +090045File::File(RValue other)
46 : file_(other.object->TakePlatformFile()),
47 error_(other.object->error()),
48 created_(other.object->created()),
49 async_(other.object->async_) {
50}
51
52File::~File() {
53 Close();
54}
55
56File& File::operator=(RValue other) {
57 if (this != other.object) {
58 Close();
59 SetPlatformFile(other.object->TakePlatformFile());
60 error_ = other.object->error();
61 created_ = other.object->created();
62 async_ = other.object->async_;
63 }
64 return *this;
65}
66
rvargas@chromium.orge207eae2014-01-04 07:14:15 +090067#if !defined(OS_NACL)
68void File::Initialize(const FilePath& name, uint32 flags) {
69 if (name.ReferencesParent()) {
70 error_ = FILE_ERROR_ACCESS_DENIED;
71 return;
72 }
73 InitializeUnsafe(name, flags);
74}
75#endif
76
rvargas@google.comb1ae3192013-11-28 10:31:31 +090077} // namespace base