-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.h
51 lines (42 loc) · 1.74 KB
/
utils.h
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
#pragma once
#include <cstdarg>
#include <cstdint>
#include <string>
#include <vector>
#if defined(__MINGW32__)
// https://stackoverflow.com/questions/40159892/using-asprintf-on-windows
#ifndef _vscprintf
/* For some reason, MSVC fails to honour this #ifndef. */
/* Hence function renamed to _vscprintf_so(). */
int _vscprintf_so(const char * format, va_list pargs);
#endif // _vscprintf
#ifndef vasprintf
int vasprintf(char **strp, const char *fmt, va_list ap);
#endif // vasprintf
#ifndef asprintf
int asprintf(char *strp[], const char *fmt, ...);
#endif // asprintf
#endif
ssize_t READ (const int fd, uint8_t *whereto, size_t len);
ssize_t WRITE(const int fd, const uint8_t *whereto, size_t len);
std::vector<std::string> split(std::string in, const std::string & splitter);
std::string myformat(const char *const fmt, ...);
uint32_t get_free_heap_space();
uint64_t get_uint64_t(const uint8_t *const p);
uint32_t get_uint32_t(const uint8_t *const p);
uint64_t get_micros();
uint64_t get_millis();
void teensyMAC(uint8_t *const mac);
void encode_lun(uint8_t *const target, const uint64_t lun_nr);
uint8_t * duplicate_new(const void *const in, const size_t n);
std::string to_hex(const uint8_t *const in, const size_t n);
// Apple has NTOHL/etc macros that confuse the build
uint32_t my_NTOHL(const uint32_t x);
uint16_t my_NTOHS(const uint16_t x);
uint32_t my_HTONL(const uint32_t x);
uint16_t my_HTONS(const uint16_t x);
#define my_HTONLL(x) ((1==my_HTONL(1)) ? (x) : (((uint64_t)my_HTONL((x) & 0xFFFFFFFFUL)) << 32) | my_HTONL((uint32_t)((x) >> 32)))
#define my_NTOHLL(x) ((1==my_NTOHL(1)) ? (x) : (((uint64_t)my_NTOHL((x) & 0xFFFFFFFFUL)) << 32) | my_NTOHL((uint32_t)((x) >> 32)))
void socket_set_nodelay(const int fd);
extern uint64_t running_since;
void my_yield();