• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1  // Copyright 2016 The Chromium OS 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 "bsdiff/memory_file.h"
6  
7  #include <algorithm>
8  #include <string.h>
9  
10  namespace bsdiff {
11  
MemoryFile(const uint8_t * data,size_t size)12  MemoryFile::MemoryFile(const uint8_t* data, size_t size)
13      : data_(data), size_(size) {}
14  
Read(void * buf,size_t count,size_t * bytes_read)15  bool MemoryFile::Read(void* buf, size_t count, size_t* bytes_read) {
16    count = std::min(count, static_cast<size_t>(size_ - offset_));
17    memcpy(buf, data_ + offset_, count);
18    offset_ += count;
19    *bytes_read = count;
20    return true;
21  }
22  
Write(const void * buf,size_t count,size_t * bytes_written)23  bool MemoryFile::Write(const void* buf, size_t count, size_t* bytes_written) {
24    return false;
25  }
26  
Seek(off_t pos)27  bool MemoryFile::Seek(off_t pos) {
28    if (pos > static_cast<off_t>(size_) || pos < 0)
29      return false;
30    offset_ = pos;
31    return true;
32  }
33  
Close()34  bool MemoryFile::Close() {
35    return true;
36  }
37  
GetSize(uint64_t * size)38  bool MemoryFile::GetSize(uint64_t* size) {
39    *size = size_;
40    return true;
41  }
42  
43  }  // namespace bsdiff
44