#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#include <stdint.h>
#include <stdbool.h>
#include <unistd.h>
#include <time.h>
#include <machine/endian.h>
Go to the source code of this file.
|
#define | calloc_a(len, ...) __calloc_a(len, ##__VA_ARGS__, NULL) |
|
#define | ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) |
|
#define | __BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) |
|
#define | BUILD_BUG_ON __BUILD_BUG_ON |
|
#define | _GNUC_MIN_VER(maj, min) 0 |
|
#define | __BYTE_ORDER BYTE_ORDER |
|
#define | __BIG_ENDIAN BIG_ENDIAN |
|
#define | __LITTLE_ENDIAN LITTLE_ENDIAN |
|
#define | __constant_swap16(x) |
|
#define | __constant_swap32(x) |
|
#define | __constant_swap64(x) |
|
#define | __is_constant(x) (sizeof(int) == sizeof(*(1 ? ((void*)((long)(x) * 0l)) : (int*)1))) |
|
#define | __eval_once(func, x) ({ __typeof__(x) __x = x; func(__x); }) |
|
#define | __eval_safe(func, x) |
|
#define | const_cpu_to_be64(x) __constant_swap64(x) |
|
#define | const_cpu_to_be32(x) __constant_swap32(x) |
|
#define | const_cpu_to_be16(x) __constant_swap16(x) |
|
#define | const_be64_to_cpu(x) __constant_swap64(x) |
|
#define | const_be32_to_cpu(x) __constant_swap32(x) |
|
#define | const_be16_to_cpu(x) __constant_swap16(x) |
|
#define | const_cpu_to_le64(x) (x) |
|
#define | const_cpu_to_le32(x) (x) |
|
#define | const_cpu_to_le16(x) (x) |
|
#define | const_le64_to_cpu(x) (x) |
|
#define | const_le32_to_cpu(x) (x) |
|
#define | const_le16_to_cpu(x) (x) |
|
#define | cpu_to_be64(x) __eval_safe(__constant_swap64, x) |
|
#define | cpu_to_be32(x) __eval_safe(__constant_swap32, x) |
|
#define | cpu_to_be16(x) __eval_safe(__constant_swap16, x) |
|
#define | be64_to_cpu(x) __eval_safe(__constant_swap64, x) |
|
#define | be32_to_cpu(x) __eval_safe(__constant_swap32, x) |
|
#define | be16_to_cpu(x) __eval_safe(__constant_swap16, x) |
|
#define | cpu_to_le64(x) (x) |
|
#define | cpu_to_le32(x) (x) |
|
#define | cpu_to_le16(x) (x) |
|
#define | le64_to_cpu(x) (x) |
|
#define | le32_to_cpu(x) (x) |
|
#define | le16_to_cpu(x) (x) |
|
#define | __packed __attribute__((packed)) |
|
#define | __constructor __attribute__((constructor)) |
|
#define | __destructor __attribute__((destructor)) |
|
#define | __hidden __attribute__((visibility("hidden"))) |
|
#define | __has_attribute(x) 0 |
|
#define | fallthrough do {} while (0) /* fallthrough */ |
|
#define | B64_ENCODE_LEN(_len) ((((_len) + 2) / 3) * 4 + 1) |
|
#define | B64_DECODE_LEN(_len) (((_len) / 4) * 3 + 1) |
|
|
void * | __calloc_a (size_t len,...) |
|
int | b64_encode (const void *src, size_t src_len, void *dest, size_t dest_len) |
|
int | b64_decode (const void *src, void *dest, size_t dest_len) |
|
static unsigned int | cbuf_order (unsigned int x) |
|
static unsigned long | cbuf_size (int order) |
|
void * | cbuf_alloc (unsigned int order) |
|
void | cbuf_free (void *ptr, unsigned int order) |
|
int | mkdir_p (char *dir, mode_t mask) |
|
◆ __BIG_ENDIAN
#define __BIG_ENDIAN BIG_ENDIAN |
◆ __BUILD_BUG_ON
#define __BUILD_BUG_ON |
( |
|
condition | ) |
((void)sizeof(char[1 - 2*!!(condition)])) |
◆ __BYTE_ORDER
#define __BYTE_ORDER BYTE_ORDER |
◆ __constant_swap16
#define __constant_swap16 |
( |
|
x | ) |
|
Value: ((uint16_t)( \
(((uint16_t)(x) & (uint16_t)0x00ffU) << 8) | \
(((uint16_t)(x) & (uint16_t)0xff00U) >> 8)))
Definition at line 101 of file utils.h.
◆ __constant_swap32
#define __constant_swap32 |
( |
|
x | ) |
|
Value: ((uint32_t)( \
(((uint32_t)(x) & (uint32_t)0x000000ffUL) << 24) | \
(((uint32_t)(x) & (uint32_t)0x0000ff00UL) << 8) | \
(((uint32_t)(x) & (uint32_t)0x00ff0000UL) >> 8) | \
(((uint32_t)(x) & (uint32_t)0xff000000UL) >> 24)))
Definition at line 105 of file utils.h.
◆ __constant_swap64
#define __constant_swap64 |
( |
|
x | ) |
|
Value: ((uint64_t)( \
(((uint64_t)(x) & (uint64_t)0x00000000000000ffULL) << 56) | \
(((uint64_t)(x) & (uint64_t)0x000000000000ff00ULL) << 40) | \
(((uint64_t)(x) & (uint64_t)0x0000000000ff0000ULL) << 24) | \
(((uint64_t)(x) & (uint64_t)0x00000000ff000000ULL) << 8) | \
(((uint64_t)(x) & (uint64_t)0x000000ff00000000ULL) >> 8) | \
(((uint64_t)(x) & (uint64_t)0x0000ff0000000000ULL) >> 24) | \
(((uint64_t)(x) & (uint64_t)0x00ff000000000000ULL) >> 40) | \
(((uint64_t)(x) & (uint64_t)0xff00000000000000ULL) >> 56)))
Definition at line 111 of file utils.h.
◆ __constructor
◆ __destructor
◆ __eval_once
#define __eval_once |
( |
|
func, |
|
|
|
x |
|
) |
| ({ __typeof__(x) __x = x; func(__x); }) |
◆ __eval_safe
#define __eval_safe |
( |
|
func, |
|
|
|
x |
|
) |
| |
Value:
#define __eval_once(func, x)
Definition at line 139 of file utils.h.
◆ __has_attribute
#define __has_attribute |
( |
|
x | ) |
0 |
◆ __hidden
◆ __is_constant
#define __is_constant |
( |
|
x | ) |
(sizeof(int) == sizeof(*(1 ? ((void*)((long)(x) * 0l)) : (int*)1))) |
◆ __LITTLE_ENDIAN
#define __LITTLE_ENDIAN LITTLE_ENDIAN |
◆ __packed
◆ _GNUC_MIN_VER
#define _GNUC_MIN_VER |
( |
|
maj, |
|
|
|
min |
|
) |
| 0 |
◆ ARRAY_SIZE
#define ARRAY_SIZE |
( |
|
arr | ) |
(sizeof(arr) / sizeof((arr)[0])) |
◆ B64_DECODE_LEN
#define B64_DECODE_LEN |
( |
|
_len | ) |
(((_len) / 4) * 3 + 1) |
◆ B64_ENCODE_LEN
#define B64_ENCODE_LEN |
( |
|
_len | ) |
((((_len) + 2) / 3) * 4 + 1) |
◆ be16_to_cpu
◆ be32_to_cpu
◆ be64_to_cpu
◆ BUILD_BUG_ON
◆ calloc_a
#define calloc_a |
( |
|
len, |
|
|
|
... |
|
) |
| __calloc_a(len, ##__VA_ARGS__, NULL) |
◆ const_be16_to_cpu
◆ const_be32_to_cpu
◆ const_be64_to_cpu
◆ const_cpu_to_be16
◆ const_cpu_to_be32
◆ const_cpu_to_be64
◆ const_cpu_to_le16
#define const_cpu_to_le16 |
( |
|
x | ) |
(x) |
◆ const_cpu_to_le32
#define const_cpu_to_le32 |
( |
|
x | ) |
(x) |
◆ const_cpu_to_le64
#define const_cpu_to_le64 |
( |
|
x | ) |
(x) |
◆ const_le16_to_cpu
#define const_le16_to_cpu |
( |
|
x | ) |
(x) |
◆ const_le32_to_cpu
#define const_le32_to_cpu |
( |
|
x | ) |
(x) |
◆ const_le64_to_cpu
#define const_le64_to_cpu |
( |
|
x | ) |
(x) |
◆ cpu_to_be16
◆ cpu_to_be32
◆ cpu_to_be64
◆ cpu_to_le16
#define cpu_to_le16 |
( |
|
x | ) |
(x) |
◆ cpu_to_le32
#define cpu_to_le32 |
( |
|
x | ) |
(x) |
◆ cpu_to_le64
#define cpu_to_le64 |
( |
|
x | ) |
(x) |
◆ fallthrough
#define fallthrough do {} while (0) /* fallthrough */ |
◆ le16_to_cpu
#define le16_to_cpu |
( |
|
x | ) |
(x) |
◆ le32_to_cpu
#define le32_to_cpu |
( |
|
x | ) |
(x) |
◆ le64_to_cpu
#define le64_to_cpu |
( |
|
x | ) |
(x) |
◆ __calloc_a()
void* __calloc_a |
( |
size_t |
len, |
|
|
|
... |
|
) |
| |
Definition at line 35 of file utils.c.
51 ptr = calloc(1, alloc_len);
59 *cur_addr = &ptr[alloc_len];
#define foreach_arg(_arg, _addr, _len, _first_addr, _first_len)
◆ b64_decode()
int b64_decode |
( |
const void * |
src, |
|
|
void * |
dest, |
|
|
size_t |
dest_len |
|
) |
| |
Definition at line 203 of file base64.c.
205 const char *src = _src;
206 unsigned char *target = dest;
215 assert(dest && targsize > 0);
217 while ((ch = (
unsigned char)*src++) !=
'\0') {
231 if (tarindex >= targsize)
233 target[tarindex] = (pos -
Base64) << 2;
239 if (tarindex >= targsize)
241 target[tarindex] |= (pos -
Base64) >> 4;
242 nextbyte = ((pos -
Base64) & 0x0f) << 4;
243 if (tarindex + 1 < targsize)
244 target[tarindex+1] = nextbyte;
253 if (tarindex >= targsize)
255 target[tarindex] |= (pos -
Base64) >> 2;
256 nextbyte = ((pos -
Base64) & 0x03) << 6;
257 if (tarindex + 1 < targsize)
258 target[tarindex+1] = nextbyte;
267 if (tarindex >= targsize)
269 target[tarindex] |= (pos -
Base64);
283 ch = (
unsigned char)*src++;
291 for (; ch !=
'\0'; ch = (
unsigned char)*src++)
297 ch = (
unsigned char)*src++;
306 for (; ch !=
'\0'; ch = (
unsigned char)*src++)
316 if (target && tarindex < targsize &&
317 target[tarindex] != 0)
330 if (tarindex < targsize)
331 target[tarindex] = 0;
static const char Base64[]
◆ b64_encode()
int b64_encode |
( |
const void * |
src, |
|
|
size_t |
src_len, |
|
|
void * |
dest, |
|
|
size_t |
dest_len |
|
) |
| |
Definition at line 139 of file base64.c.
142 const unsigned char *src = _src;
144 size_t datalength = 0;
145 u_char input[3] = {0};
149 assert(dest && targsize > 0);
151 while (2 < srclength) {
157 output[0] = input[0] >> 2;
158 output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
159 output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
160 output[3] = input[2] & 0x3f;
162 if (datalength + 4 > targsize)
164 target[datalength++] =
Base64[output[0]];
165 target[datalength++] =
Base64[output[1]];
166 target[datalength++] =
Base64[output[2]];
167 target[datalength++] =
Base64[output[3]];
171 if (0 != srclength) {
173 input[0] = input[1] = input[2] =
'\0';
174 for (i = 0; i < srclength; i++)
177 output[0] = input[0] >> 2;
178 output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
179 output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
181 if (datalength + 4 > targsize)
183 target[datalength++] =
Base64[output[0]];
184 target[datalength++] =
Base64[output[1]];
186 target[datalength++] =
Pad64;
188 target[datalength++] =
Base64[output[2]];
189 target[datalength++] =
Pad64;
191 if (datalength >= targsize)
193 target[datalength] =
'\0';
◆ cbuf_alloc()
void* cbuf_alloc |
( |
unsigned int |
order | ) |
|
Definition at line 116 of file utils.c.
118 char path[] =
"/tmp/cbuf-XXXXXX";
133 #ifndef MAP_ANONYMOUS
134 #define MAP_ANONYMOUS MAP_ANON
137 ret = mmap(NULL, size * 2, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0);
138 if (ret == MAP_FAILED) {
143 if (mmap(ret, size, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_SHARED,
145 mmap(ret + size, size, PROT_READ | PROT_WRITE,
146 MAP_FIXED | MAP_SHARED,
fd, 0) != ret + size) {
147 munmap(ret, size * 2);
static unsigned long cbuf_size(int order)
◆ cbuf_free()
void cbuf_free |
( |
void * |
ptr, |
|
|
unsigned int |
order |
|
) |
| |
◆ cbuf_order()
static unsigned int cbuf_order |
( |
unsigned int |
x | ) |
|
|
inlinestatic |
Definition at line 250 of file utils.h.
252 return 32 - __builtin_clz(x - 1);
◆ cbuf_size()
static unsigned long cbuf_size |
( |
int |
order | ) |
|
|
inlinestatic |
Definition at line 255 of file utils.h.
257 unsigned long page_size = sysconf(_SC_PAGESIZE);
258 unsigned long ret = 1ULL << order;
static unsigned int page_size
◆ mkdir_p()
int mkdir_p |
( |
char * |
dir, |
|
|
mode_t |
mask |
|
) |
| |
Definition at line 161 of file utils.c.
166 ret = mkdir(dir, mask);
167 if (!ret || errno == EEXIST)
170 if (ret && (errno != ENOENT))
173 l = strrchr(dir,
'/');
184 ret = mkdir(dir, mask);
185 if (!ret || errno == EEXIST)
int mkdir_p(char *dir, mode_t mask)