Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/psx/mednadisc/FileStream.h
2 views
1
/* Mednafen - Multi-system Emulator
2
*
3
* This program is free software; you can redistribute it and/or modify
4
* it under the terms of the GNU General Public License as published by
5
* the Free Software Foundation; either version 2 of the License, or
6
* (at your option) any later version.
7
*
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
*/
17
18
#ifndef __MDFN_FILESTREAM_H
19
#define __MDFN_FILESTREAM_H
20
21
#include "Stream.h"
22
#include "error.h"
23
24
#include <stdio.h>
25
#include <string>
26
27
class FileStream : public Stream
28
{
29
public:
30
31
enum
32
{
33
MODE_READ = 0,
34
MODE_WRITE,
35
MODE_WRITE_SAFE, // Will throw an exception instead of overwriting an existing file.
36
MODE_WRITE_INPLACE, // Like MODE_WRITE, but won't truncate the file if it already exists.
37
};
38
39
FileStream(const std::string& path, const int mode);
40
virtual ~FileStream() override;
41
42
virtual uint64 attributes(void) override;
43
44
virtual uint8 *map(void) noexcept override;
45
virtual uint64 map_size(void) noexcept override;
46
virtual void unmap(void) noexcept override;
47
48
virtual uint64 read(void *data, uint64 count, bool error_on_eos = true) override;
49
virtual void write(const void *data, uint64 count) override;
50
virtual void truncate(uint64 length) override;
51
virtual void seek(int64 offset, int whence) override;
52
virtual uint64 tell(void) override;
53
virtual uint64 size(void) override;
54
virtual void flush(void) override;
55
virtual void close(void) override;
56
57
virtual int get_line(std::string &str) override;
58
59
INLINE int get_char(void)
60
{
61
int ret;
62
63
errno = 0;
64
ret = fgetc(fp);
65
66
if(MDFN_UNLIKELY(errno != 0))
67
{
68
ErrnoHolder ene(errno);
69
throw(MDFN_Error(ene.Errno(), ("Error reading from opened file \"%s\": %s"), path_save.c_str(), ene.StrError()));
70
}
71
return(ret);
72
}
73
74
private:
75
FileStream & operator=(const FileStream &); // Assignment operator
76
FileStream(const FileStream &); // Copy constructor
77
//FileStream(FileStream &); // Copy constructor
78
79
FILE *fp;
80
std::string path_save;
81
const int OpenedMode;
82
83
void* mapping;
84
uint64 mapping_size;
85
};
86
87
88
89
#endif
90
91