-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.cpp
38 lines (31 loc) · 926 Bytes
/
util.cpp
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
#include "util.h"
size_t WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp) {
size_t realsize = size * nmemb;
struct MemoryStruct *mem = (struct MemoryStruct *)userp;
char *ptr = (char*) realloc(mem->memory, mem->size + realsize + 1);
if(ptr == NULL) {
printf("error: not enough memory\n");
return 0;
}
mem->memory = ptr;
memcpy(&(mem->memory[mem->size]), contents, realsize);
mem->size += realsize;
mem->memory[mem->size] = 0;
//mem->onFinish(mem->memory, mem->size);
return realsize;
}
int32_t asago_bytes_to_int(char *buffer)
{
int32_t some = 0;
some |= (unsigned char)buffer[0];
some |= (unsigned char)buffer[1] << 8;
some |= (unsigned char)buffer[2] << 16;
some |= (unsigned char)buffer[3] << 24;
return some;
}
double asago_bytes_to_double(char *buffer)
{
double some;
memcpy(&some, buffer, sizeof(double));
return some;
}