mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-06 08:03:34 +07:00
62 lines
2.2 KiB
C
62 lines
2.2 KiB
C
#pragma once
|
|
|
|
#include "arch.h"
|
|
#include "str.h"
|
|
|
|
char *mg_file_read(const char *path, size_t *size);
|
|
bool mg_file_write(const char *path, const void *buf, size_t len);
|
|
bool mg_file_printf(const char *path, const char *fmt, ...);
|
|
void mg_random(void *buf, size_t len);
|
|
bool mg_globmatch(const char *pattern, size_t plen, const char *s, size_t n);
|
|
bool mg_commalist(struct mg_str *s, struct mg_str *k, struct mg_str *v);
|
|
uint16_t mg_ntohs(uint16_t net);
|
|
uint32_t mg_ntohl(uint32_t net);
|
|
uint32_t mg_crc32(uint32_t crc, const char *buf, size_t len);
|
|
char *mg_hexdump(const void *buf, size_t len);
|
|
char *mg_hex(const void *buf, size_t len, char *dst);
|
|
void mg_unhex(const char *buf, size_t len, unsigned char *to);
|
|
unsigned long mg_unhexn(const char *s, size_t len);
|
|
int mg_asprintf(char **buf, size_t size, const char *fmt, ...);
|
|
int mg_vasprintf(char **buf, size_t size, const char *fmt, va_list ap);
|
|
int64_t mg_to64(struct mg_str str);
|
|
int mg_check_ip_acl(struct mg_str acl, uint32_t remote_ip);
|
|
double mg_time(void);
|
|
unsigned long mg_millis(void);
|
|
void mg_usleep(unsigned long usecs);
|
|
|
|
#define mg_htons(x) mg_ntohs(x)
|
|
#define mg_htonl(x) mg_ntohl(x)
|
|
|
|
// Expands to a string representation of its argument: e.g.
|
|
// MG_STRINGIFY_LITERAL(5) expands to "5"
|
|
#if !defined(_MSC_VER) || _MSC_VER >= 1900
|
|
#define MG_STRINGIFY_LITERAL(...) #__VA_ARGS__
|
|
#else
|
|
#define MG_STRINGIFY_LITERAL(x) #x
|
|
#endif
|
|
// Expands to a string representation of its argument, which can be a macro:
|
|
// #define FOO 123
|
|
// MG_STRINGIFY_MACRO(FOO) // Expands to 123
|
|
#define MG_STRINGIFY_MACRO(x) MG_STRINGIFY_LITERAL(x)
|
|
|
|
// Linked list management macros
|
|
#define LIST_ADD_HEAD(type_, head_, elem_) \
|
|
do { \
|
|
(elem_)->next = (*head_); \
|
|
*(head_) = (elem_); \
|
|
} while (0)
|
|
|
|
#define LIST_ADD_TAIL(type_, head_, elem_) \
|
|
do { \
|
|
type_ **h = head_; \
|
|
while (*h != NULL) h = &(*h)->next; \
|
|
*h = (elem_); \
|
|
} while (0)
|
|
|
|
#define LIST_DELETE(type_, head_, elem_) \
|
|
do { \
|
|
type_ **h = head_; \
|
|
while (*h != (elem_)) h = &(*h)->next; \
|
|
*h = (elem_)->next; \
|
|
} while (0)
|