1761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes/*
2761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes * Copyright (C) 2009 The Android Open Source Project
3761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes *
4761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes * Licensed under the Apache License, Version 2.0 (the "License");
5761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes * you may not use this file except in compliance with the License.
6761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes * You may obtain a copy of the License at
7761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes *
8761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes *      http://www.apache.org/licenses/LICENSE-2.0
9761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes *
10761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes * Unless required by applicable law or agreed to in writing, software
11761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes * distributed under the License is distributed on an "AS IS" BASIS,
12761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes * See the License for the specific language governing permissions and
14761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes * limitations under the License.
15761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes */
16761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes
17fc0e3219edc9a5bf81b166e82fd5db2796eb6a0dBrian Carlstrom#ifndef ART_RUNTIME_BASE_UNIX_FILE_NULL_FILE_H_
18fc0e3219edc9a5bf81b166e82fd5db2796eb6a0dBrian Carlstrom#define ART_RUNTIME_BASE_UNIX_FILE_NULL_FILE_H_
19761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes
20761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes#include "base/unix_file/random_access_file.h"
21761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes#include "base/macros.h"
22761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes
23761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughesnamespace unix_file {
24761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes
25761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes// A RandomAccessFile implementation equivalent to /dev/null. Writes are
26761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes// discarded, and there's no data to be read. Callers could use FdFile in
27761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes// conjunction with /dev/null, but that's not portable and costs a file
28761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes// descriptor. NullFile is "free".
29761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes//
30761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes// Thread safe.
31761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughesclass NullFile : public RandomAccessFile {
32761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes public:
33761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes  NullFile();
34761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes  virtual ~NullFile();
35761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes
36761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes  // RandomAccessFile API.
37761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes  virtual int Close();
38761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes  virtual int Flush();
39761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes  virtual int64_t Read(char* buf, int64_t byte_count, int64_t offset) const;
40761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes  virtual int SetLength(int64_t new_length);
41761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes  virtual int64_t GetLength() const;
42761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes  virtual int64_t Write(const char* buf, int64_t byte_count, int64_t offset);
43761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes
44761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes private:
45761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes  DISALLOW_COPY_AND_ASSIGN(NullFile);
46761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes};
47761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes
48761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes}  // namespace unix_file
49761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes
50fc0e3219edc9a5bf81b166e82fd5db2796eb6a0dBrian Carlstrom#endif  // ART_RUNTIME_BASE_UNIX_FILE_NULL_FILE_H_
51