Support dvb-box on openembedded build tree.
[vuplus_xbmc] / tools / TexturePacker / SimpleFS.h
1 #pragma once
2
3 /*
4  *      Copyright (C) 2005-2013 Team XBMC
5  *      http://xbmc.org
6  *
7  *  This Program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2, or (at your option)
10  *  any later version.
11  *
12  *  This Program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with XBMC; see the file COPYING.  If not, see
19  *  <http://www.gnu.org/licenses/>.
20  *
21  */
22
23 #include <stdio.h>
24 #include <string>
25 #include <stdint.h>
26
27 class CFile
28 {
29 public:
30   CFile()
31   {
32     m_file = NULL;
33   }
34
35   bool Open(const std::string &file)
36   {
37     Close();
38     m_file = fopen(file.c_str(), "rb");
39     return NULL != m_file;
40   }
41
42   bool OpenForWrite(const std::string &file, bool overwrite)
43   {
44     Close();
45     m_file = fopen(file.c_str(), "wb");
46     return NULL != m_file;
47   }
48   void Close()
49   {
50     if (m_file)
51       fclose(m_file);
52     m_file = NULL;
53   }
54
55   uint64_t Read(void *data, uint64_t size)
56   {
57     if (fread(data, size, 1, m_file) == 1)
58       return size;
59     return 0;
60   }
61
62   uint64_t Write(const void *data, uint64_t size)
63   {
64     if (fwrite(data, size, 1, m_file) == 1)
65       return size;
66     return 0;
67   }
68
69 private:
70   FILE* m_file;
71 };