-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcommon.cpp
More file actions
56 lines (45 loc) · 1.3 KB
/
common.cpp
File metadata and controls
56 lines (45 loc) · 1.3 KB
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
#include "common.h"
Com_DPrintf_t Com_DPrintf = (Com_DPrintf_t)0x435820;
Com_Printf_t Com_Printf = (Com_Printf_t)0x4357B0;
Com_Error_t Com_Error = (Com_Error_t)0x435AD0;
Cmd_RemoveCommand_t Cmd_RemoveCommand = (Cmd_RemoveCommand_t)0x428990;
Cmd_AddCommand_t Cmd_AddCommand = (Cmd_AddCommand_t)0x428840;
int Q_vsnprintf(char *dest, int size, const char *fmt, va_list argptr) {
int ret;
#ifdef _WIN32
#undef _vsnprintf
ret = _vsnprintf(dest, size - 1, fmt, argptr);
#define _vsnprintf use_idStr_vsnPrintf
#else
#undef vsnprintf
ret = vsnprintf(dest, size, fmt, argptr);
#define vsnprintf use_idStr_vsnPrintf
#endif
dest[size - 1] = '\0';
if (ret < 0 || ret >= size) {
return -1;
}
return ret;
}
char *va(char *format, ...) {
va_list argptr;
#define MAX_VA_STRING 32000
static char temp_buffer[MAX_VA_STRING];
static char string[MAX_VA_STRING]; // in case va is called by nested functions
static int index = 0;
char *buf;
int len;
va_start(argptr, format);
vsprintf(temp_buffer, format, argptr);
va_end(argptr);
if ((len = strlen(temp_buffer)) >= MAX_VA_STRING) {
Com_Error( ERR_DROP, "Attempted to overrun string in call to va()\n" );
}
if (len + index >= MAX_VA_STRING - 1) {
index = 0;
}
buf = &string[index];
memcpy(buf, temp_buffer, len + 1);
index += len + 1;
return buf;
}