-
Notifications
You must be signed in to change notification settings - Fork 0
/
dummy.c
204 lines (161 loc) · 2.91 KB
/
dummy.c
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#include <fcntl.h>
#include <sys/types.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/mman.h>
#include <stdarg.h>
#include <sys/stat.h>
static char* mmapfile(const char* fn, size_t* size);
int vm_debugLevel = 0;
void Com_Printf( const char *fmt, ... )
{
va_list ap;
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
return;
}
#if 0
void* VM_ValueToSymbol(void)
{
return NULL;
}
void* VM_ValueToFunctionSymbol()
{
return NULL;
}
#endif
void* va(void)
{
return NULL;
}
void Com_Error( int level, const char *error, ... )
{
va_list ap;
va_start(ap, error);
vfprintf(stderr, error, ap);
va_end(ap);
fputc('\n', stderr);
exit(99);
return;
}
void* Hunk_Alloc(size_t size)
{
return malloc(size);
}
void *Hunk_AllocDebug( int size, int preference, char *label, char *file, int line )
{
return Hunk_Alloc(size);
}
void Cmd_AddCommand( void)
{
}
void Com_Memset (void* dest, const int val, const size_t count)
{
memset(dest, val, count);
}
void Com_sprintf( char *dest, int size, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vsnprintf(dest, size, fmt, ap);
va_end(ap);
return;
}
void *Z_Malloc(int size)
{
return malloc(size);
}
void *Z_MallocDebug( int size, char *label, char *file, int line )
{
return Z_Malloc(size);
}
void Z_Free (void *ptr)
{
free(ptr);
}
void Sys_UnloadDll( void *dllHandle )
{
}
int Hunk_MemoryRemaining( void )
{
return 420000;
}
void FS_FreeFile(void *buf)
{
free(buf);
}
void COM_StripExtension( const char *in, char *out )
{
out = "";
}
char *COM_Parse (char *data)
{
return NULL;
}
void Q_strncpyz( char *dest, const char *src, int destsize ) {
strncpy( dest, src, destsize-1 );
dest[destsize-1] = 0;
}
int Q_stricmp (char *s1, char *s2)
{
return strcmp (s1, s2);
}
long FS_ReadFileDir(const char *qpath, void *searchPath, int unpure, void **buffer)
{
size_t size;
char* mem;
if(strrchr(qpath, '/'))
{
qpath = strrchr(qpath, '/')+1;
}
mem = mmapfile(qpath, &size);
if(!mem)
goto out_error;
*buffer = malloc(size);
memcpy(*buffer, mem, size);
Com_Printf("%s (%d bytes) loaded\n", qpath, size);
munmap(mem, 0);
return size;
out_error:
*buffer = NULL;
return -1;
}
long FS_ReadFile(const char *qpath, void **buffer)
{
return FS_ReadFileDir(qpath, NULL, 0, buffer);
}
static char* mmapfile(const char* fn, size_t* size)
{
int fd = -1;
char* mem = NULL;
struct stat stb;
fd = open(fn, O_RDONLY);
if(fd == -1)
goto out;
if(fstat(fd, &stb) == -1)
goto out;
*size = stb.st_size;
mem = mmap(NULL, stb.st_size, PROT_READ|PROT_EXEC, MAP_SHARED, fd, 0);
if(mem == (void*)-1)
mem = NULL;
out:
if(fd != -1)
close(fd);
return mem;
}
int LongSwap (int l)
{
unsigned char b1,b2,b3,b4;
b1 = l&255;
b2 = (l>>8)&255;
b3 = (l>>16)&255;
b4 = (l>>24)&255;
return ((int)b1<<24) + ((int)b2<<16) + ((int)b3<<8) + b4;
}
int FS_Which(const char *filename, void *searchPath)
{
return 1;
}