-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.cpp
36 lines (30 loc) · 995 Bytes
/
utils.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
//
// Created by Administrator on 2019/9/27 0027.
//
#include "utils.h"
unsigned long long ntohll(unsigned long long val) {
if (__BYTE_ORDER == __LITTLE_ENDIAN) {
return (((unsigned long long) htonl((int) ((val << 32) >> 32))) << 32) |
(unsigned int) htonl((int) (val >> 32));
} else if (__BYTE_ORDER == __BIG_ENDIAN) {
return val;
}
}
unsigned long long htonll(unsigned long long val) {
if (__BYTE_ORDER == __LITTLE_ENDIAN) {
return (((unsigned long long) htonl((int) ((val << 32) >> 32))) << 32) |
(unsigned int) htonl((int) (val >> 32));
} else if (__BYTE_ORDER == __BIG_ENDIAN) {
return val;
}
}
void gen_random(char *s, const int len) {
static const char alphanum[] =
"0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
for (int i = 0; i < len; ++i) {
s[i] = alphanum[rand() % (sizeof(alphanum) - 1)];
}
s[len] = 0;
}