1// Aseprite Document IO Library
2// Copyright (c) 2018 David Capello
3//
4// This file is released under the terms of the MIT license.
5// Read LICENSE.txt for more information.
6
7#include "dio/file_interface.h"
8
9namespace dio {
10
11StdioFileInterface::StdioFileInterface(FILE* file)
12 : m_file(file)
13 , m_ok(true)
14{
15}
16
17bool StdioFileInterface::ok() const
18{
19 return m_ok;
20}
21
22size_t StdioFileInterface::tell()
23{
24 return ftell(m_file);
25}
26
27void StdioFileInterface::seek(size_t absPos)
28{
29 fseek(m_file, absPos, SEEK_SET);
30}
31
32uint8_t StdioFileInterface::read8()
33{
34 int value = fgetc(m_file);
35 if (value != EOF)
36 return value;
37
38 m_ok = false;
39 return 0;
40}
41
42size_t StdioFileInterface::readBytes(uint8_t* buf, size_t n)
43{
44 int n2 = fread(buf, 1, n, m_file);
45 if (n2 != n)
46 m_ok = false;
47 return n2;
48}
49
50void StdioFileInterface::write8(uint8_t value)
51{
52 fputc(value, m_file);
53}
54
55} // namespace dio
56