Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/psx/octoshock/FileWrapper.h
2 views
1
#ifndef __MDFN_FILEWRAPPER_H
2
#define __MDFN_FILEWRAPPER_H
3
4
// A stdio FILE wrapper(with some BSD and POSIXisms, and a little dash of Win32, thrown in for special behaviors)
5
class FileWrapper
6
{
7
public:
8
9
enum
10
{
11
MODE_READ = 0,
12
MODE_WRITE,
13
MODE_WRITE_SAFE // Will throw an exception instead of overwriting an existing file.
14
};
15
16
FileWrapper(const char *path, const int mode, const char *purpose = NULL);
17
~FileWrapper();
18
19
uint64 read(void *data, uint64 count, bool error_on_eof = true);
20
21
void write(const void *data, uint64 count);
22
23
int scanf(const char *format, ...) MDFN_FORMATSTR(scanf, 2, 3);
24
25
void put_char(int c);
26
27
void put_string(const char *str);
28
void put_string(const std::string &str);
29
30
char *get_line(char *s, int size); // Same semantics as fgets(), for now
31
32
void seek(int64 offset, int whence);
33
34
int64 tell(void);
35
36
int64 size(void);
37
38
void flush(void);
39
40
void close(void); // Flushes and closes the underlying OS/C lib file. Calling any other method of this class after a call to
41
// this method is illegal(except for the implicit call to the destructor).
42
//
43
// This is necessary since there can be errors when closing a file, and we can't safely throw an
44
// exception from the destructor.
45
//
46
// Manually calling this method isn't strictly necessary, it'll be called from the destructor
47
// automatically, but calling is strongly recommended when the file is opened for writing.
48
private:
49
50
FileWrapper & operator=(const FileWrapper &); // Assignment operator
51
FileWrapper(const FileWrapper &); // Copy constructor
52
53
FILE *fp;
54
const int OpenedMode;
55
};
56
57
#endif
58
59