forked from wmcbrine/tivodecode-ng
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhappyfile.hxx
78 lines (58 loc) · 1.23 KB
/
happyfile.hxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* tivodecode-ng
* Copyright 2006-2015, Jeremy Drake et al.
* See COPYING file for license terms
*/
#ifndef HAPPY_FILE_H_
#define HAPPY_FILE_H_
#include "tdconfig.h"
#include <stddef.h>
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#if defined(WIN32)
# include <io.h>
#endif
#include <cstdio>
#ifndef RAWBUFSIZE
#define RAWBUFSIZE 65536
#endif
#ifndef BUFFERSIZE
#define BUFFERSIZE 4096
#endif
#if SIZEOF_OFF_T == 8
typedef off_t hoff_t;
#elif defined (WIN32)
typedef __int64 hoff_t;
#else
#warning Large file support is questionable on this platform
typedef off_t hoff_t;
#endif
class HappyFile
{
private:
FILE *fh;
bool attached;
hoff_t pos;
/* buffer stuff */
hoff_t buffer_start;
hoff_t buffer_fill;
char rawbuf[RAWBUFSIZE];
char buffer[BUFFERSIZE];
void init();
public:
int open(const char *filename, const char *mode);
int attach(FILE *fh);
int close();
size_t read(void *ptr, size_t size);
size_t write(void *ptr, size_t size);
hoff_t tell();
int seek(hoff_t offset);
};
#endif