OCT 1. 更新格式化代码

This commit is contained in:
huangxin 2022-12-02 14:42:15 +08:00
parent f82cb95c05
commit abd393322d
35 changed files with 6334 additions and 6149 deletions

View File

@ -2,6 +2,7 @@
Language: Cpp
AccessModifierOffset: -4
InsertBraces: true
AlignArrayOfStructures: Left
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: Consecutive
AlignConsecutiveAssignments: Consecutive
@ -26,8 +27,9 @@ AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: MultiLine
AttributeMacros:
- __capability
- __unused
BinPackArguments: false
BinPackParameters: true
BinPackParameters: false
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
@ -57,7 +59,7 @@ BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 140
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: true
ConstructorInitializerAllOnOneLineOrOnePerLine: true
@ -174,7 +176,7 @@ SpaceAroundPointerQualifiers: Default
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 0
SpacesBeforeTrailingComments: 4
SpacesInAngles: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: false
@ -199,3 +201,6 @@ WhitespaceSensitiveMacros:
- BOOST_PP_STRINGIZE
- NS_SWIFT_NAME
- CF_SWIFT_NAME
TypenameMacros:
- CONFIG_ITEM
- PCONFIG_ITEM

File diff suppressed because it is too large Load Diff

View File

@ -188,50 +188,110 @@ ARG_EXTERN struct arg_rem *arg_rem(const char *datatype, const char *glossary);
ARG_EXTERN struct arg_lit *arg_lit0(const char *shortopts, const char *longopts, const char *glossary);
ARG_EXTERN struct arg_lit *arg_lit1(const char *shortopts, const char *longopts, const char *glossary);
ARG_EXTERN struct arg_lit *arg_litn(const char *shortopts, const char *longopts, int mincount, int maxcount,
ARG_EXTERN struct arg_lit *arg_litn(const char *shortopts,
const char *longopts,
int mincount,
int maxcount,
const char *glossary);
ARG_EXTERN struct arg_int *arg_int0(const char *shortopts, const char *longopts, const char *datatype,
ARG_EXTERN struct arg_int *arg_int0(const char *shortopts,
const char *longopts,
const char *datatype,
const char *glossary);
ARG_EXTERN struct arg_int *arg_int1(const char *shortopts, const char *longopts, const char *datatype,
ARG_EXTERN struct arg_int *arg_int1(const char *shortopts,
const char *longopts,
const char *datatype,
const char *glossary);
ARG_EXTERN struct arg_int *arg_intn(const char *shortopts,
const char *longopts,
const char *datatype,
int mincount,
int maxcount,
const char *glossary);
ARG_EXTERN struct arg_int *arg_intn(const char *shortopts, const char *longopts, const char *datatype, int mincount,
int maxcount, const char *glossary);
ARG_EXTERN struct arg_dbl *arg_dbl0(const char *shortopts, const char *longopts, const char *datatype,
ARG_EXTERN struct arg_dbl *arg_dbl0(const char *shortopts,
const char *longopts,
const char *datatype,
const char *glossary);
ARG_EXTERN struct arg_dbl *arg_dbl1(const char *shortopts, const char *longopts, const char *datatype,
ARG_EXTERN struct arg_dbl *arg_dbl1(const char *shortopts,
const char *longopts,
const char *datatype,
const char *glossary);
ARG_EXTERN struct arg_dbl *arg_dbln(const char *shortopts,
const char *longopts,
const char *datatype,
int mincount,
int maxcount,
const char *glossary);
ARG_EXTERN struct arg_dbl *arg_dbln(const char *shortopts, const char *longopts, const char *datatype, int mincount,
int maxcount, const char *glossary);
ARG_EXTERN struct arg_str *arg_str0(const char *shortopts, const char *longopts, const char *datatype,
ARG_EXTERN struct arg_str *arg_str0(const char *shortopts,
const char *longopts,
const char *datatype,
const char *glossary);
ARG_EXTERN struct arg_str *arg_str1(const char *shortopts, const char *longopts, const char *datatype,
ARG_EXTERN struct arg_str *arg_str1(const char *shortopts,
const char *longopts,
const char *datatype,
const char *glossary);
ARG_EXTERN struct arg_str *arg_strn(const char *shortopts,
const char *longopts,
const char *datatype,
int mincount,
int maxcount,
const char *glossary);
ARG_EXTERN struct arg_str *arg_strn(const char *shortopts, const char *longopts, const char *datatype, int mincount,
int maxcount, const char *glossary);
ARG_EXTERN struct arg_rex *arg_rex0(const char *shortopts, const char *longopts, const char *pattern,
const char *datatype, int flags, const char *glossary);
ARG_EXTERN struct arg_rex *arg_rex1(const char *shortopts, const char *longopts, const char *pattern,
const char *datatype, int flags, const char *glossary);
ARG_EXTERN struct arg_rex *arg_rexn(const char *shortopts, const char *longopts, const char *pattern,
const char *datatype, int mincount, int maxcount, int flags, const char *glossary);
ARG_EXTERN struct arg_file *arg_file0(const char *shortopts, const char *longopts, const char *datatype,
ARG_EXTERN struct arg_rex *arg_rex0(const char *shortopts,
const char *longopts,
const char *pattern,
const char *datatype,
int flags,
const char *glossary);
ARG_EXTERN struct arg_file *arg_file1(const char *shortopts, const char *longopts, const char *datatype,
ARG_EXTERN struct arg_rex *arg_rex1(const char *shortopts,
const char *longopts,
const char *pattern,
const char *datatype,
int flags,
const char *glossary);
ARG_EXTERN struct arg_rex *arg_rexn(const char *shortopts,
const char *longopts,
const char *pattern,
const char *datatype,
int mincount,
int maxcount,
int flags,
const char *glossary);
ARG_EXTERN struct arg_file *arg_filen(const char *shortopts, const char *longopts, const char *datatype, int mincount,
int maxcount, const char *glossary);
ARG_EXTERN struct arg_date *arg_date0(const char *shortopts, const char *longopts, const char *format,
const char *datatype, const char *glossary);
ARG_EXTERN struct arg_date *arg_date1(const char *shortopts, const char *longopts, const char *format,
const char *datatype, const char *glossary);
ARG_EXTERN struct arg_date *arg_daten(const char *shortopts, const char *longopts, const char *format,
const char *datatype, int mincount, int maxcount, const char *glossary);
ARG_EXTERN struct arg_file *arg_file0(const char *shortopts,
const char *longopts,
const char *datatype,
const char *glossary);
ARG_EXTERN struct arg_file *arg_file1(const char *shortopts,
const char *longopts,
const char *datatype,
const char *glossary);
ARG_EXTERN struct arg_file *arg_filen(const char *shortopts,
const char *longopts,
const char *datatype,
int mincount,
int maxcount,
const char *glossary);
ARG_EXTERN struct arg_date *arg_date0(const char *shortopts,
const char *longopts,
const char *format,
const char *datatype,
const char *glossary);
ARG_EXTERN struct arg_date *arg_date1(const char *shortopts,
const char *longopts,
const char *format,
const char *datatype,
const char *glossary);
ARG_EXTERN struct arg_date *arg_daten(const char *shortopts,
const char *longopts,
const char *format,
const char *datatype,
int mincount,
int maxcount,
const char *glossary);
ARG_EXTERN struct arg_end *arg_end(int maxerrors);
@ -242,14 +302,20 @@ ARG_EXTERN struct arg_end *arg_end(int maxerrors);
/**** other functions *******************************************/
ARG_EXTERN int arg_nullcheck(void **argtable);
ARG_EXTERN int arg_parse(int argc, char **argv, void **argtable);
ARG_EXTERN void arg_print_option(FILE *fp, const char *shortopts, const char *longopts, const char *datatype,
ARG_EXTERN void arg_print_option(FILE *fp,
const char *shortopts,
const char *longopts,
const char *datatype,
const char *suffix);
ARG_EXTERN void arg_print_syntax(FILE *fp, void **argtable, const char *suffix);
ARG_EXTERN void arg_print_syntaxv(FILE *fp, void **argtable, const char *suffix);
ARG_EXTERN void arg_print_glossary(FILE *fp, void **argtable, const char *format);
ARG_EXTERN void arg_print_glossary_gnu(FILE *fp, void **argtable);
ARG_EXTERN void arg_print_errors(FILE *fp, struct arg_end *end, const char *progname);
ARG_EXTERN void arg_print_option_ds(arg_dstr_t ds, const char *shortopts, const char *longopts, const char *datatype,
ARG_EXTERN void arg_print_option_ds(arg_dstr_t ds,
const char *shortopts,
const char *longopts,
const char *datatype,
const char *suffix);
ARG_EXTERN void arg_print_syntax_ds(arg_dstr_t ds, void **argtable, const char *suffix);
ARG_EXTERN void arg_print_syntaxv_ds(arg_dstr_t ds, void **argtable, const char *suffix);
@ -285,8 +351,13 @@ ARG_EXTERN void arg_mgsort(void *data, int size, int esize, int i, in
ARG_EXTERN void arg_make_get_help_msg(arg_dstr_t res);
ARG_EXTERN void arg_make_help_msg(arg_dstr_t ds, char *cmd_name, void **argtable);
ARG_EXTERN void arg_make_syntax_err_msg(arg_dstr_t ds, void **argtable, struct arg_end *end);
ARG_EXTERN int arg_make_syntax_err_help_msg(arg_dstr_t ds, char *name, int help, int nerrors, void **argtable,
struct arg_end *end, int *exitcode);
ARG_EXTERN int arg_make_syntax_err_help_msg(arg_dstr_t ds,
char *name,
int help,
int nerrors,
void **argtable,
struct arg_end *end,
int *exitcode);
ARG_EXTERN void arg_set_module_name(const char *name);
ARG_EXTERN void arg_set_module_version(int major, int minor, int patch, const char *tag);

View File

@ -77,7 +77,11 @@ static void onEVPWorkCb(uv_work_t *pWork) {
}
}
int evp_add_crypto_task(CRYPTO_TYPE type, unsigned char *pInBuf, unsigned int iSize, unsigned char *pOutBuf, char *pKey,
int evp_add_crypto_task(CRYPTO_TYPE type,
unsigned char *pInBuf,
unsigned int iSize,
unsigned char *pOutBuf,
char *pKey,
on_evp_crypto onEvpCryptCb) {
uv_work_t *puvWork = NULL;
PCRYPT_TASK_PARAMS pTask = NULL;

View File

@ -92,7 +92,10 @@ int hash_digest_file(HASH_TYPE hashType, const char *pFileName, char **pHashValu
* @param pHashValue
* @return
*/
int hash_digest_mem(HASH_TYPE hashType, const unsigned char *pBuf, unsigned int iBufLen, unsigned char **pHashValue,
int hash_digest_mem(HASH_TYPE hashType,
const unsigned char *pBuf,
unsigned int iBufLen,
unsigned char **pHashValue,
unsigned int *pOutSize) {
EVP_MD_CTX *pCtx;

View File

@ -110,8 +110,12 @@ static int sha1prng_for_aes_key(const char *pKey, unsigned char *pShaPrng16) {
} \
} while (0)
int symmetric_decrypto(AES_TYPE algorithmType, unsigned char *pInBuf, unsigned int inSize, unsigned char **pOutBuf,
int *pOutSize, const char *pKey) {
int symmetric_decrypto(AES_TYPE algorithmType,
unsigned char *pInBuf,
unsigned int inSize,
unsigned char **pOutBuf,
int *pOutSize,
const char *pKey) {
int enBytes = 0;
EVP_CIPHER_CTX *pCtx;
unsigned char *pAesBuf;
@ -180,8 +184,12 @@ int symmetric_decrypto(AES_TYPE algorithmType, unsigned char *pInBuf, unsigned i
return ERR_SUCCESS;
}
int symmetric_encrypto(AES_TYPE algorithmType, unsigned char *pInBuf, unsigned int inSize, unsigned char **pOutBuf,
int *pOutSize, const char *pKey) {
int symmetric_encrypto(AES_TYPE algorithmType,
unsigned char *pInBuf,
unsigned int inSize,
unsigned char **pOutBuf,
int *pOutSize,
const char *pKey) {
int enBytes = 0;
unsigned char *pAesBuf;
EVP_CIPHER_CTX *pCtx;

View File

@ -38,16 +38,27 @@ typedef enum {
HASH_TYPE_SHA256 = 2,
} HASH_TYPE;
typedef void (*on_evp_crypto)(CRYPTO_TYPE type, const unsigned char *pData, unsigned int iSize,
const unsigned char *pSrcData, int iError);
typedef void (*on_evp_crypto)(CRYPTO_TYPE type,
const unsigned char *pData,
unsigned int iSize,
const unsigned char *pSrcData,
int iError);
//*****************************************************
// AES
//*****************************************************
int symmetric_encrypto(AES_TYPE algorithmType, unsigned char *pInBuf, unsigned int inSize, unsigned char **pOutBuf,
int *pOutSize, const char *pKey);
int symmetric_decrypto(AES_TYPE algorithmType, unsigned char *pInBuf, unsigned int inSize, unsigned char **pOutBuf,
int *pOutSize, const char *pKey);
int symmetric_encrypto(AES_TYPE algorithmType,
unsigned char *pInBuf,
unsigned int inSize,
unsigned char **pOutBuf,
int *pOutSize,
const char *pKey);
int symmetric_decrypto(AES_TYPE algorithmType,
unsigned char *pInBuf,
unsigned int inSize,
unsigned char **pOutBuf,
int *pOutSize,
const char *pKey);
//*****************************************************
// BASE64
//*****************************************************
@ -62,13 +73,20 @@ unsigned char *base64_decode(const char *pBase64, unsigned int *pOutSize);
// MD5
//*****************************************************
int hash_digest_file(HASH_TYPE hashType, const char *pFileName, char **pHashValue);
int hash_digest_mem(HASH_TYPE hashType, const unsigned char *pBuf, unsigned int iBufLen, unsigned char **pHashValue,
int hash_digest_mem(HASH_TYPE hashType,
const unsigned char *pBuf,
unsigned int iBufLen,
unsigned char **pHashValue,
unsigned int *pOutSize);
//*****************************************************
// Async Engine
//*****************************************************
int evp_add_crypto_task(CRYPTO_TYPE type, unsigned char *pInBuf, unsigned int iSize, unsigned char *pOutBuf, char *pKey,
int evp_add_crypto_task(CRYPTO_TYPE type,
unsigned char *pInBuf,
unsigned int iSize,
unsigned char *pOutBuf,
char *pKey,
on_evp_crypto onEvpCryptCb);
void evp_system_init(void);

View File

@ -10,13 +10,23 @@ extern "C" {
int inet_api_init(void);
typedef void (*on_http_response)(void *pData, unsigned int size, const char *pReqUrl, const char *pDlPath,
const char *pTaskUuid, int iFinished, void *pUserData);
typedef void (*on_progress_changed)(const char *pReqUrl, const char *pTaskUuid, unsigned char uPercent,
typedef void (*on_http_response)(void *pData,
unsigned int size,
const char *pReqUrl,
const char *pDlPath,
const char *pTaskUuid,
int iFinished,
void *pUserData);
typedef void (*on_progress_changed)(const char *pReqUrl,
const char *pTaskUuid,
unsigned char uPercent,
void *pUserData);
const char *inet_download_file_async(const char *pURL, const char *pPath, on_http_response onRespCb,
on_progress_changed onProgressCb, void *pData);
const char *inet_download_file_async(const char *pURL,
const char *pPath,
on_http_response onRespCb,
on_progress_changed onProgressCb,
void *pData);
#ifdef __cplusplus
}

View File

@ -50,7 +50,10 @@ int copy_file(const char *pSrc, const char *pDest);
char *bin2hex(char *p, const unsigned char *cp, unsigned int count);
int shell_with_output(const char *pCmd, char **pResult);
int str_to_mac(const char *str, unsigned char mac[6]);
int get_nic_info(const char *pName, unsigned int *pIp, unsigned int *pNetmask, unsigned int *pGateway,
int get_nic_info(const char *pName,
unsigned int *pIp,
unsigned int *pNetmask,
unsigned int *pGateway,
unsigned char *pMac);
int str_to_ipaddr(const char *pIp, unsigned int *ipAddr);
#ifdef __cplusplus

View File

@ -24,8 +24,7 @@
#define cJSON__h
#ifdef __cplusplus
extern "C"
{
extern "C" {
#endif
#if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32))
@ -100,8 +99,7 @@ then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJ
#define cJSON_StringIsConst 512
/* The cJSON structure: */
typedef struct cJSON
{
typedef struct cJSON {
/* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
struct cJSON *next;
struct cJSON *prev;
@ -122,8 +120,7 @@ typedef struct cJSON
char *string;
} cJSON;
typedef struct cJSON_Hooks
{
typedef struct cJSON_Hooks {
/* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */
void *(CJSON_CDECL *malloc_fn)(size_t sz);
void(CJSON_CDECL *free_fn)(void *ptr);
@ -149,8 +146,13 @@ CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value);
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, size_t buffer_length);
/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */
/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */
CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated);
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated);
CJSON_PUBLIC(cJSON *)
cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated);
CJSON_PUBLIC(cJSON *)
cJSON_ParseWithLengthOpts(const char *value,
size_t buffer_length,
const char **return_parse_end,
cJSON_bool require_null_terminated);
/* Render a cJSON entity to text for transfer/storage. */
CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item);
@ -160,7 +162,8 @@ CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item);
CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt);
/* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */
/* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */
CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format);
CJSON_PUBLIC(cJSON_bool)
cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format);
/* Delete a cJSON entity and all subentities. */
CJSON_PUBLIC(void) cJSON_Delete(cJSON *item);
@ -239,7 +242,8 @@ CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string)
CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string);
/* Update array items. */
CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */
CJSON_PUBLIC(cJSON_bool)
cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON *const parent, cJSON *const item, cJSON *replacement);
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem);
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem);
@ -266,7 +270,8 @@ CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * co
CJSON_PUBLIC(cJSON *) cJSON_AddFalseToObject(cJSON *const object, const char *const name);
CJSON_PUBLIC(cJSON *) cJSON_AddBoolToObject(cJSON *const object, const char *const name, const cJSON_bool boolean);
CJSON_PUBLIC(cJSON *) cJSON_AddNumberToObject(cJSON *const object, const char *const name, const double number);
CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string);
CJSON_PUBLIC(cJSON *)
cJSON_AddStringToObject(cJSON *const object, const char *const name, const char *const string);
CJSON_PUBLIC(cJSON *) cJSON_AddRawToObject(cJSON *const object, const char *const name, const char *const raw);
CJSON_PUBLIC(cJSON *) cJSON_AddObjectToObject(cJSON *const object, const char *const name);
CJSON_PUBLIC(cJSON *) cJSON_AddArrayToObject(cJSON *const object, const char *const name);
@ -275,12 +280,14 @@ CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * c
#define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number))
/* helper for the cJSON_SetNumberValue macro */
CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number);
#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number))
#define cJSON_SetNumberValue(object, number) \
((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number))
/* Change the valuestring of a cJSON_String object, only takes effect when type of object is cJSON_String */
CJSON_PUBLIC(char *) cJSON_SetValuestring(cJSON *object, const char *valuestring);
/* Macro for iterating over an array or object */
#define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
#define cJSON_ArrayForEach(element, array) \
for (element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
/* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */
CJSON_PUBLIC(void *) cJSON_malloc(size_t size);

View File

@ -220,22 +220,14 @@ typedef struct {
for (; index_##_element < realsize_##_element && index_##_element < size; index_##_element++) { \
array_item_##_element = cJSON_GetArrayItem(array_##_element, index_##_element); \
if (array_item_##_element) { \
S2J_STRUCT_ARRAY_GET_ELEMENT_EX(to_struct, \
array_item_##_element, \
type, \
_element, \
index_##_element, \
_defval); \
S2J_STRUCT_ARRAY_GET_ELEMENT_EX( \
to_struct, array_item_##_element, type, _element, index_##_element, _defval); \
} \
} \
} else { \
for (; index_##_element < realsize_##_element && index_##_element < size; index_##_element++) { \
S2J_STRUCT_ARRAY_GET_ELEMENT_EX(to_struct, \
array_##_element, \
type, \
_element, \
index_##_element, \
_defval); \
S2J_STRUCT_ARRAY_GET_ELEMENT_EX( \
to_struct, array_##_element, type, _element, index_##_element, _defval); \
} \
} \
} else { \

View File

@ -134,12 +134,10 @@ static inline size_t sdsavail(const sds s) {
static inline void sdssetlen(sds s, size_t newlen) {
unsigned char flags = s[-1];
switch (flags & SDS_TYPE_MASK) {
case SDS_TYPE_5:
{
case SDS_TYPE_5: {
unsigned char *fp = ((unsigned char *)s) - 1;
*fp = (unsigned char)(SDS_TYPE_5 | (newlen << SDS_TYPE_BITS));
}
break;
} break;
case SDS_TYPE_8:
SDS_HDR(8, s)->len = (uint8_t)newlen;
break;
@ -158,13 +156,11 @@ static inline void sdssetlen(sds s, size_t newlen) {
static inline void sdsinclen(sds s, size_t inc) {
unsigned char flags = s[-1];
switch (flags & SDS_TYPE_MASK) {
case SDS_TYPE_5:
{
case SDS_TYPE_5: {
unsigned char *fp = ((unsigned char *)s) - 1;
unsigned char newlen = SDS_TYPE_5_LEN(flags) + (unsigned char)inc;
*fp = SDS_TYPE_5 | (newlen << SDS_TYPE_BITS);
}
break;
} break;
case SDS_TYPE_8:
SDS_HDR(8, s)->len += (uint8_t)inc;
break;
@ -233,8 +229,7 @@ sds sdscpy(sds s, const char *t);
sds sdscatvprintf(sds s, const char *fmt, va_list ap);
#ifdef __GNUC__
sds sdscatprintf(sds s, const char *fmt, ...)
__attribute__((format(printf, 2, 3)));
sds sdscatprintf(sds s, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
#else
sds sdscatprintf(sds s, const char *fmt, ...);
#endif

File diff suppressed because it is too large Load Diff

View File

@ -47,10 +47,8 @@ struct sqlite3_api_routines {
int (*busy_timeout)(sqlite3 *, int ms);
int (*changes)(sqlite3 *);
int (*close)(sqlite3 *);
int (*collation_needed)(sqlite3*,void*,void(*)(void*,sqlite3*,
int eTextRep,const char*));
int (*collation_needed16)(sqlite3*,void*,void(*)(void*,sqlite3*,
int eTextRep,const void*));
int (*collation_needed)(sqlite3 *, void *, void (*)(void *, sqlite3 *, int eTextRep, const char *));
int (*collation_needed16)(sqlite3 *, void *, void (*)(void *, sqlite3 *, int eTextRep, const void *));
const void *(*column_blob)(sqlite3_stmt *, int iCol);
int (*column_bytes)(sqlite3_stmt *, int iCol);
int (*column_bytes16)(sqlite3_stmt *, int iCol);
@ -75,15 +73,26 @@ struct sqlite3_api_routines {
void *(*commit_hook)(sqlite3 *, int (*)(void *), void *);
int (*complete)(const char *sql);
int (*complete16)(const void *sql);
int (*create_collation)(sqlite3*,const char*,int,void*,
int (
*create_collation)(sqlite3 *, const char *, int, void *, int (*)(void *, int, const void *, int, const void *));
int (*create_collation16)(sqlite3 *,
const void *,
int,
void *,
int (*)(void *, int, const void *, int, const void *));
int (*create_collation16)(sqlite3*,const void*,int,void*,
int(*)(void*,int,const void*,int,const void*));
int (*create_function)(sqlite3*,const char*,int,int,void*,
int (*create_function)(sqlite3 *,
const char *,
int,
int,
void *,
void (*xFunc)(sqlite3_context *, int, sqlite3_value **),
void (*xStep)(sqlite3_context *, int, sqlite3_value **),
void (*xFinal)(sqlite3_context *));
int (*create_function16)(sqlite3*,const void*,int,int,void*,
int (*create_function16)(sqlite3 *,
const void *,
int,
int,
void *,
void (*xFunc)(sqlite3_context *, int, sqlite3_value **),
void (*xStep)(sqlite3_context *, int, sqlite3_value **),
void (*xFinal)(sqlite3_context *));
@ -131,19 +140,26 @@ struct sqlite3_api_routines {
void (*result_text16le)(sqlite3_context *, const void *, int, void (*)(void *));
void (*result_value)(sqlite3_context *, sqlite3_value *);
void *(*rollback_hook)(sqlite3 *, void (*)(void *), void *);
int (*set_authorizer)(sqlite3*,int(*)(void*,int,const char*,const char*,
const char*,const char*),void*);
int (*set_authorizer)(sqlite3 *,
int (*)(void *, int, const char *, const char *, const char *, const char *),
void *);
void (*set_auxdata)(sqlite3_context *, int, void *, void (*)(void *));
char *(*xsnprintf)(int, char *, const char *, ...);
int (*step)(sqlite3_stmt *);
int (*table_column_metadata)(sqlite3*,const char*,const char*,const char*,
char const**,char const**,int*,int*,int*);
int (*table_column_metadata)(sqlite3 *,
const char *,
const char *,
const char *,
char const **,
char const **,
int *,
int *,
int *);
void (*thread_cleanup)(void);
int (*total_changes)(sqlite3 *);
void *(*trace)(sqlite3 *, void (*xTrace)(void *, const char *), void *);
int (*transfer_bindings)(sqlite3_stmt *, sqlite3_stmt *);
void * (*update_hook)(sqlite3*,void(*)(void*,int ,char const*,char const*,
sqlite_int64),void*);
void *(*update_hook)(sqlite3 *, void (*)(void *, int, char const *, char const *, sqlite_int64), void *);
void *(*user_data)(sqlite3_context *);
const void *(*value_blob)(sqlite3_value *);
int (*value_bytes)(sqlite3_value *);
@ -165,17 +181,18 @@ struct sqlite3_api_routines {
int (*prepare16_v2)(sqlite3 *, const void *, int, sqlite3_stmt **, const void **);
int (*clear_bindings)(sqlite3_stmt *);
/* Added by 3.4.1 */
int (*create_module_v2)(sqlite3*,const char*,const sqlite3_module*,void*,
void (*xDestroy)(void *));
int (*create_module_v2)(sqlite3 *, const char *, const sqlite3_module *, void *, void (*xDestroy)(void *));
/* Added by 3.5.0 */
int (*bind_zeroblob)(sqlite3_stmt *, int, int);
int (*blob_bytes)(sqlite3_blob *);
int (*blob_close)(sqlite3_blob *);
int (*blob_open)(sqlite3*,const char*,const char*,const char*,sqlite3_int64,
int,sqlite3_blob**);
int (*blob_open)(sqlite3 *, const char *, const char *, const char *, sqlite3_int64, int, sqlite3_blob **);
int (*blob_read)(sqlite3_blob *, void *, int, int);
int (*blob_write)(sqlite3_blob *, const void *, int, int);
int (*create_collation_v2)(sqlite3*,const char*,int,void*,
int (*create_collation_v2)(sqlite3 *,
const char *,
int,
void *,
int (*)(void *, int, const void *, int, const void *),
void (*)(void *));
int (*file_control)(sqlite3 *, const char *, int, void *);
@ -213,7 +230,11 @@ struct sqlite3_api_routines {
int (*backup_step)(sqlite3_backup *, int);
const char *(*compileoption_get)(int);
int (*compileoption_used)(const char *);
int (*create_function_v2)(sqlite3*,const char*,int,int,void*,
int (*create_function_v2)(sqlite3 *,
const char *,
int,
int,
void *,
void (*xFunc)(sqlite3_context *, int, sqlite3_value **),
void (*xStep)(sqlite3_context *, int, sqlite3_value **),
void (*xFinal)(sqlite3_context *),
@ -250,20 +271,16 @@ struct sqlite3_api_routines {
int (*wal_checkpoint_v2)(sqlite3 *, const char *, int, int *, int *);
/* Version 3.8.7 and later */
int (*auto_extension)(void (*)(void));
int (*bind_blob64)(sqlite3_stmt*,int,const void*,sqlite3_uint64,
void(*)(void*));
int (*bind_text64)(sqlite3_stmt*,int,const char*,sqlite3_uint64,
void(*)(void*),unsigned char);
int (*bind_blob64)(sqlite3_stmt *, int, const void *, sqlite3_uint64, void (*)(void *));
int (*bind_text64)(sqlite3_stmt *, int, const char *, sqlite3_uint64, void (*)(void *), unsigned char);
int (*cancel_auto_extension)(void (*)(void));
int (*load_extension)(sqlite3 *, const char *, const char *, char **);
void *(*malloc64)(sqlite3_uint64);
sqlite3_uint64 (*msize)(void *);
void *(*realloc64)(void *, sqlite3_uint64);
void (*reset_auto_extension)(void);
void (*result_blob64)(sqlite3_context*,const void*,sqlite3_uint64,
void(*)(void*));
void (*result_text64)(sqlite3_context*,const char*,sqlite3_uint64,
void(*)(void*), unsigned char);
void (*result_blob64)(sqlite3_context *, const void *, sqlite3_uint64, void (*)(void *));
void (*result_text64)(sqlite3_context *, const char *, sqlite3_uint64, void (*)(void *), unsigned char);
int (*strglob)(const char *, const char *);
/* Version 3.8.11 and later */
sqlite3_value *(*value_dup)(const sqlite3_value *);
@ -285,10 +302,8 @@ struct sqlite3_api_routines {
/* Version 3.18.0 and later */
void (*set_last_insert_rowid)(sqlite3 *, sqlite3_int64);
/* Version 3.20.0 and later */
int (*prepare_v3)(sqlite3*,const char*,int,unsigned int,
sqlite3_stmt**,const char**);
int (*prepare16_v3)(sqlite3*,const void*,int,unsigned int,
sqlite3_stmt**,const void**);
int (*prepare_v3)(sqlite3 *, const char *, int, unsigned int, sqlite3_stmt **, const char **);
int (*prepare16_v3)(sqlite3 *, const void *, int, unsigned int, sqlite3_stmt **, const void **);
int (*bind_pointer)(sqlite3_stmt *, int, void *, const char *, void (*)(void *));
void (*result_pointer)(sqlite3_context *, void *, const char *, void (*)(void *));
void *(*value_pointer)(sqlite3_value *, const char *);
@ -311,7 +326,11 @@ struct sqlite3_api_routines {
int (*str_length)(sqlite3_str *);
char *(*str_value)(sqlite3_str *);
/* Version 3.25.0 and later */
int (*create_window_function)(sqlite3*,const char*,int,int,void*,
int (*create_window_function)(sqlite3 *,
const char *,
int,
int,
void *,
void (*xStep)(sqlite3_context *, int, sqlite3_value **),
void (*xFinal)(sqlite3_context *),
void (*xValue)(sqlite3_context *),
@ -331,8 +350,7 @@ struct sqlite3_api_routines {
const char *(*filename_journal)(const char *);
const char *(*filename_wal)(const char *);
/* Version 3.32.0 and later */
char *(*create_filename)(const char*,const char*,const char*,
int,const char**);
char *(*create_filename)(const char *, const char *, const char *, int, const char **);
void (*free_filename)(char *);
sqlite3_file *(*database_file_object)(const char *);
/* Version 3.34.0 and later */
@ -343,7 +361,8 @@ struct sqlite3_api_routines {
/* Version 3.37.0 and later */
int (*autovacuum_pages)(sqlite3 *,
unsigned int (*)(void *, const char *, unsigned int, unsigned int, unsigned int),
void*, void(*)(void*));
void *,
void (*)(void *));
/* Version 3.38.0 and later */
int (*error_offset)(sqlite3 *);
int (*vtab_rhs_value)(sqlite3_index_info *, int, sqlite3_value **);
@ -352,10 +371,8 @@ struct sqlite3_api_routines {
int (*vtab_in_first)(sqlite3_value *, sqlite3_value **);
int (*vtab_in_next)(sqlite3_value *, sqlite3_value **);
/* Version 3.39.0 and later */
int (*deserialize)(sqlite3*,const char*,unsigned char*,
sqlite3_int64,sqlite3_int64,unsigned);
unsigned char *(*serialize)(sqlite3*,const char *,sqlite3_int64*,
unsigned int);
int (*deserialize)(sqlite3 *, const char *, unsigned char *, sqlite3_int64, sqlite3_int64, unsigned);
unsigned char *(*serialize)(sqlite3 *, const char *, sqlite3_int64 *, unsigned int);
const char *(*db_name)(sqlite3 *, int);
};
@ -363,8 +380,7 @@ struct sqlite3_api_routines {
** This is the function signature used for all extension entry points. It
** is also defined in the file "loadext.c".
*/
typedef int (*sqlite3_loadext_entry)(
sqlite3 *db, /* Handle to the sqlitecipher. */
typedef int (*sqlite3_loadext_entry)(sqlite3 *db, /* Handle to the sqlitecipher. */
char **pzErrMsg, /* Used to set error string on failure. */
const sqlite3_api_routines *pThunk /* Extension API function pointers. */
);
@ -688,8 +704,7 @@ typedef int (*sqlite3_loadext_entry)(
** extension */
#define SQLITE_EXTENSION_INIT1 const sqlite3_api_routines *sqlite3_api = 0;
#define SQLITE_EXTENSION_INIT2(v) sqlite3_api = v;
# define SQLITE_EXTENSION_INIT3 \
extern const sqlite3_api_routines *sqlite3_api;
#define SQLITE_EXTENSION_INIT3 extern const sqlite3_api_routines *sqlite3_api;
#else
/* This case when the file is being statically linked into the
** application */

View File

@ -221,9 +221,8 @@ typedef struct {
} \
} \
if ((a)->i > ((pos) + (len))) { \
memmove(_utarray_eltptr(a, pos), \
_utarray_eltptr(a, (pos) + (len)), \
((a)->i - ((pos) + (len))) * (a)->icd.sz); \
memmove( \
_utarray_eltptr(a, pos), _utarray_eltptr(a, (pos) + (len)), ((a)->i - ((pos) + (len))) * (a)->icd.sz); \
} \
(a)->i -= (len); \
} while (0)
@ -274,9 +273,10 @@ static void utarray_str_cpy(void *dst, const void *src) {
}
static void utarray_str_dtor(void *elt) {
char **eltc = (char **)elt;
if (*eltc != NULL)
if (*eltc != NULL) {
free(*eltc);
}
}
static const UT_icd ut_str_icd UTARRAY_UNUSED = {sizeof(char *), NULL, utarray_str_cpy, utarray_str_dtor};
static const UT_icd ut_int_icd UTARRAY_UNUSED = {sizeof(int), NULL, NULL, NULL};
static const UT_icd ut_ptr_icd UTARRAY_UNUSED = {sizeof(void *), NULL, NULL, NULL};

View File

@ -226,8 +226,8 @@ typedef unsigned char uint8_t;
(head)->hh.tbl->num_buckets = HASH_INITIAL_NUM_BUCKETS; \
(head)->hh.tbl->log2_num_buckets = HASH_INITIAL_NUM_BUCKETS_LOG2; \
(head)->hh.tbl->hho = (char *)(&(head)->hh) - (char *)(head); \
(head)->hh.tbl->buckets = \
(UT_hash_bucket *)uthash_malloc(HASH_INITIAL_NUM_BUCKETS * sizeof(struct UT_hash_bucket)); \
(head)->hh.tbl->buckets = (UT_hash_bucket *)uthash_malloc(HASH_INITIAL_NUM_BUCKETS \
* sizeof(struct UT_hash_bucket)); \
(head)->hh.tbl->signature = HASH_SIGNATURE; \
if (!(head)->hh.tbl->buckets) { \
HASH_RECORD_OOM(oomed); \
@ -523,10 +523,8 @@ typedef unsigned char uint8_t;
_prev = NULL; \
while (_thh) { \
if (_prev != (char *)(_thh->hh_prev)) { \
HASH_OOPS("%s: invalid hh_prev %p, actual %p\n", \
(where), \
(void *)_thh->hh_prev, \
(void *)_prev); \
HASH_OOPS( \
"%s: invalid hh_prev %p, actual %p\n", (where), (void *)_thh->hh_prev, (void *)_prev); \
} \
_bkt_count++; \
_prev = (char *)(_thh); \
@ -888,8 +886,8 @@ typedef unsigned char uint8_t;
(tbl)->num_buckets *= 2U; \
(tbl)->log2_num_buckets++; \
(tbl)->buckets = _he_new_buckets; \
(tbl)->ineff_expands = \
((tbl)->nonideal_items > ((tbl)->num_items >> 1)) ? ((tbl)->ineff_expands + 1U) : 0U; \
(tbl)->ineff_expands = ((tbl)->nonideal_items > ((tbl)->num_items >> 1)) ? ((tbl)->ineff_expands + 1U) \
: 0U; \
if ((tbl)->ineff_expands > 1U) { \
(tbl)->noexpand = 1; \
uthash_noexpand_fyi(tbl); \

View File

@ -152,12 +152,13 @@ UTSTRING_UNUSED static void utstring_printf_va(UT_string *s, const char *fmt, va
}
/* Else try again with more space. */
if (n > -1)
if (n > -1) {
utstring_reserve(s, n + 1); /* exact */
else
} else {
utstring_reserve(s, (s->n) * 2); /* 2x */
}
}
}
#ifdef __GNUC__
/* support printf format checking (2=the format string, 3=start of varargs) */
static void utstring_printf(UT_string *s, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
@ -227,8 +228,11 @@ UTSTRING_UNUSED static void _utstring_BuildTableR(const char *P_Needle, size_t P
}
/* Search data from left to right. ( Multiple search mode. ) */
UTSTRING_UNUSED static long _utstring_find(const char *P_Haystack, size_t P_HaystackLen, const char *P_Needle,
size_t P_NeedleLen, long *P_KMP_Table) {
UTSTRING_UNUSED static long _utstring_find(const char *P_Haystack,
size_t P_HaystackLen,
const char *P_Needle,
size_t P_NeedleLen,
long *P_KMP_Table) {
long i, j;
long V_FindPosition = -1;
@ -251,8 +255,11 @@ UTSTRING_UNUSED static long _utstring_find(const char *P_Haystack, size_t P_Hays
}
/* Search data from right to left. ( Multiple search mode. ) */
UTSTRING_UNUSED static long _utstring_findR(const char *P_Haystack, size_t P_HaystackLen, const char *P_Needle,
size_t P_NeedleLen, long *P_KMP_Table) {
UTSTRING_UNUSED static long _utstring_findR(const char *P_Haystack,
size_t P_HaystackLen,
const char *P_Needle,
size_t P_NeedleLen,
long *P_KMP_Table) {
long i, j;
long V_FindPosition = -1;
@ -278,7 +285,8 @@ UTSTRING_UNUSED static long _utstring_findR(const char *P_Haystack, size_t P_Hay
/* Search data from left to right. ( One time search mode. ) */
UTSTRING_UNUSED static long utstring_find(UT_string *s,
long P_StartPosition, /* Start from 0. -1 means last position. */
const char *P_Needle, size_t P_NeedleLen) {
const char *P_Needle,
size_t P_NeedleLen) {
long V_StartPosition;
long V_HaystackLen;
long *V_KMP_Table;
@ -310,7 +318,8 @@ UTSTRING_UNUSED static long utstring_find(UT_string *s,
/* Search data from right to left. ( One time search mode. ) */
UTSTRING_UNUSED static long utstring_findR(UT_string *s,
long P_StartPosition, /* Start from 0. -1 means last position. */
const char *P_Needle, size_t P_NeedleLen) {
const char *P_Needle,
size_t P_NeedleLen) {
long V_StartPosition;
long V_HaystackLen;
long *V_KMP_Table;

View File

@ -55,7 +55,8 @@ enum ZVECT_PROPERTIES {
ZV_NONE = 0, // Sets or Resets all vector's properties to 0.
ZV_SEC_WIPE = 1 << 0, // Sets the vector for automatic Secure Wipe of items.
ZV_BYREF = 1 << 1, // Sets the vector to store items by reference instead of copying them as per default.
ZV_CIRCULAR = 1 << 2, // Sets the vector to be a circular vector (so it will not grow in capacity automatically). Elements will be overwritten as in typical circular buffers!
ZV_CIRCULAR = 1
<< 2, // Sets the vector to be a circular vector (so it will not grow in capacity automatically). Elements will be overwritten as in typical circular buffers!
ZV_NOLOCKING = 1 << 3, // This Property means the vector will not use mutexes, be careful using it!
};
@ -201,7 +202,8 @@ zvect_retval vect_unlock(vector const v);
* zvect_retval vect_lock_after_signal(const vector v);
*/
zvect_retval vect_move_on_signal(vector const v1, vector v2,
zvect_retval vect_move_on_signal(vector const v1,
vector v2,
const zvect_index s2,
const zvect_index e2,
zvect_retval (*f2)(void *, void *));
@ -591,8 +593,7 @@ void vect_copy(vector const v1, vector const v2, zvect_index start, zvect_index
* you'll have such items "inserted"
* inside v1.
*/
void vect_insert(vector const v1, vector const v2, const zvect_index s2,
const zvect_index e2, const zvect_index s1);
void vect_insert(vector const v1, vector const v2, const zvect_index s2, const zvect_index e2, const zvect_index s1);
/*
* vect_move is a function that allows to move a specified
@ -623,8 +624,11 @@ void vect_move(vector const v1, vector const v2, zvect_index start, zvect_index
* the end of v1 if check_data returns
* true.
*/
zvect_retval vect_move_if(vector const v1, vector v2, const zvect_index s2,
const zvect_index e2, zvect_retval (*f2)(void *, void *));
zvect_retval vect_move_if(vector const v1,
vector v2,
const zvect_index s2,
const zvect_index e2,
zvect_retval (*f2)(void *, void *));
/*
* vect_merge is a function that merges together 2 vectors of

View File

@ -20,8 +20,7 @@
#define macOS
#endif
#if ( defined(__GNU__) || defined(__gnu_linux__) || \
defined(__linux__) || defined(macOS) )
#if (defined(__GNU__) || defined(__gnu_linux__) || defined(__linux__) || defined(macOS))
#define OS_TYPE 1
#elif (defined(__WIN32__) || defined(WIN32) || defined(_WIN32))
#define OS_TYPE 2
@ -48,8 +47,7 @@
#define COMP_MAJRELEASE (__clang_major__)
#define COMP_MINRELEASE (__clang_minor__)
#define COMP_PATRELEASE (__clang_patchlevel__)
#elif defined(__INTEL_COMPILER) || defined(__ICC) || \
defined(__ECC) || defined(__ICL)
#elif defined(__INTEL_COMPILER) || defined(__ICC) || defined(__ECC) || defined(__ICL)
// For intel c compiler please remember to specify:
// /Qstd=c99 (on Windows)
// -std=c99 on Linux and/or macOS
@ -64,8 +62,7 @@
#define COMP_MAJRELEASE (__LCC)
#define COMP_MINRELEASE 0
#define COMP_PATRELEASE 0
#elif defined(__NORCROFT_C__) || defined(__CC_NORCROFT) || \
defined(__ARMCC_VERSION)
#elif defined(__NORCROFT_C__) || defined(__CC_NORCROFT) || defined(__ARMCC_VERSION)
// For Norcroft C please remember to specify:
// -c99
#define compiler norcroftc
@ -110,9 +107,8 @@
#elif defined(__aarch32__)
#define CPU_TYPE ARM32
#define Arch32
#elif defined(__amd64__) || defined(__x86_64__) || \
defined(__ia64__) || defined(_M_IA64) || \
defined(_M_AMD64) || defined(_M_X64)
#elif defined(__amd64__) || defined(__x86_64__) || defined(__ia64__) || defined(_M_IA64) || defined(_M_AMD64) \
|| defined(_M_X64)
#define CPU_TYPE x86_64
#define Arch64
#else
@ -126,12 +122,10 @@
#if (OS_TYPE == 1)
// We are on a Unix-like OS so we can use pthreads!
#define MUTEX_TYPE 1
# elif ( OS_TYPE == 2 ) && ( defined(__CYGWIN__) || \
defined(__MINGW32__) || defined(__MINGW64__) )
#elif (OS_TYPE == 2) && (defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__))
// We are on MS Windows using CIGWIN so we can use pthreads!
#define MUTEX_TYPE 1
# elif ( OS_TYPE == 2 ) && ( !defined(__CYGWIN__) && \
!defined(__MINGW32__) && !defined(__MINGW64__) )
#elif (OS_TYPE == 2) && (!defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(__MINGW64__))
// We are on MS Windows, so we need to use
// Windows stuff:
#define MUTEX_TYPE 2

View File

@ -36,7 +36,8 @@
// If you want a larger index you can
// change it to, for example, uint64_t
typedef uint32_t zvect_index;
#define zvect_index_max 4294967295 // If you change zvect_index type make sure you update this value
#define zvect_index_max \
4294967295 // If you change zvect_index type make sure you update this value \
// it's the maximum number that can be stored in a zvect_index.
// Default vector return type for

File diff suppressed because it is too large Load Diff

View File

@ -183,7 +183,10 @@ int str_to_ipaddr(const char *pIp, unsigned int *ipAddr) {
return ret;
}
int get_nic_info(const char *pName, unsigned int *pIp, unsigned int *pNetmask, unsigned int *pGateway,
int get_nic_info(const char *pName,
unsigned int *pIp,
unsigned int *pNetmask,
unsigned int *pGateway,
unsigned char *pMac) {
int sock;
struct ifreq ifr;

View File

@ -84,14 +84,18 @@ static inline int sdsHdrSize(char type) {
}
static inline char sdsReqType(size_t string_size) {
if (string_size < 32)
if (string_size < 32) {
return SDS_TYPE_5;
if (string_size < 0xff)
}
if (string_size < 0xff) {
return SDS_TYPE_8;
if (string_size < 0xffff)
}
if (string_size < 0xffff) {
return SDS_TYPE_16;
if (string_size < 0xffffffff)
}
if (string_size < 0xffffffff) {
return SDS_TYPE_32;
}
return SDS_TYPE_64;
}
@ -113,14 +117,19 @@ sds sdsnewlen(const void *init, size_t initlen) {
char type = sdsReqType(initlen);
/* Empty strings are usually created in order to append. Use type 8
* since type 5 is not good at this. */
if (type == SDS_TYPE_5 && initlen == 0) type = SDS_TYPE_8;
if (type == SDS_TYPE_5 && initlen == 0) {
type = SDS_TYPE_8;
}
int hdrlen = sdsHdrSize(type);
unsigned char *fp; /* flags pointer. */
sh = s_malloc(hdrlen + initlen + 1);
if (sh == NULL) return NULL;
if (!init)
if (sh == NULL) {
return NULL;
}
if (!init) {
memset(sh, 0, hdrlen + initlen + 1);
}
s = (char *)sh + hdrlen;
fp = ((unsigned char *)s) - 1;
switch (type) {
@ -157,8 +166,9 @@ sds sdsnewlen(const void *init, size_t initlen) {
break;
}
}
if (initlen && init)
if (initlen && init) {
memcpy(s, init, initlen);
}
s[initlen] = '\0';
return s;
}
@ -182,7 +192,9 @@ sds sdsdup(const sds s) {
/* Free an sds string. No operation is performed if 's' is NULL. */
void sdsfree(sds s) {
if (s == NULL) return;
if (s == NULL) {
return;
}
s_free((char *)s - sdsHdrSize(s[-1]));
}
@ -228,33 +240,42 @@ sds sdsMakeRoomFor(sds s, size_t addlen) {
int hdrlen;
/* Return ASAP if there is enough space left. */
if (avail >= addlen) return s;
if (avail >= addlen) {
return s;
}
len = sdslen(s);
sh = (char *)s - sdsHdrSize(oldtype);
newlen = (len + addlen);
if (newlen < SDS_MAX_PREALLOC)
if (newlen < SDS_MAX_PREALLOC) {
newlen *= 2;
else
} else {
newlen += SDS_MAX_PREALLOC;
}
type = sdsReqType(newlen);
/* Don't use type 5: the user is appending to the string and type 5 is
* not able to remember empty space, so sdsMakeRoomFor() must be called
* at every appending operation. */
if (type == SDS_TYPE_5) type = SDS_TYPE_8;
if (type == SDS_TYPE_5) {
type = SDS_TYPE_8;
}
hdrlen = sdsHdrSize(type);
if (oldtype == type) {
newsh = s_realloc(sh, hdrlen + newlen + 1);
if (newsh == NULL) return NULL;
if (newsh == NULL) {
return NULL;
}
s = (char *)newsh + hdrlen;
} else {
/* Since the header size changes, need to move the string forward,
* and can't use realloc */
newsh = s_malloc(hdrlen + newlen + 1);
if (newsh == NULL) return NULL;
if (newsh == NULL) {
return NULL;
}
memcpy((char *)newsh + hdrlen, s, len + 1);
s_free(sh);
s = (char *)newsh + hdrlen;
@ -282,11 +303,15 @@ sds sdsRemoveFreeSpace(sds s) {
hdrlen = sdsHdrSize(type);
if (oldtype == type) {
newsh = s_realloc(sh, hdrlen + len + 1);
if (newsh == NULL) return NULL;
if (newsh == NULL) {
return NULL;
}
s = (char *)newsh + hdrlen;
} else {
newsh = s_malloc(hdrlen + len + 1);
if (newsh == NULL) return NULL;
if (newsh == NULL) {
return NULL;
}
memcpy((char *)newsh + hdrlen, s, len + 1);
s_free(sh);
s = (char *)newsh + hdrlen;
@ -364,7 +389,8 @@ void sdsIncrLen(sds s, int incr) {
}
case SDS_TYPE_32: {
SDS_HDR_VAR(32, s);
assert((incr >= 0 && sh->alloc-sh->len >= (unsigned int)incr) || (incr < 0 && sh->len >= (unsigned int)(-incr)));
assert((incr >= 0 && sh->alloc - sh->len >= (unsigned int)incr)
|| (incr < 0 && sh->len >= (unsigned int)(-incr)));
len = (sh->len += incr);
break;
}
@ -374,7 +400,8 @@ void sdsIncrLen(sds s, int incr) {
len = (sh->len += incr);
break;
}
default: len = 0; /* Just to avoid compilation warnings. */
default:
len = 0; /* Just to avoid compilation warnings. */
}
s[len] = '\0';
}
@ -387,9 +414,13 @@ void sdsIncrLen(sds s, int incr) {
sds sdsgrowzero(sds s, size_t len) {
size_t curlen = sdslen(s);
if (len <= curlen) return s;
if (len <= curlen) {
return s;
}
s = sdsMakeRoomFor(s, len - curlen);
if (s == NULL) return NULL;
if (s == NULL) {
return NULL;
}
/* Make sure added region doesn't contain garbage */
memset(s + curlen, 0, (len - curlen + 1)); /* also set trailing \0 byte */
@ -406,7 +437,9 @@ sds sdscatlen(sds s, const void *t, size_t len) {
size_t curlen = sdslen(s);
s = sdsMakeRoomFor(s, len);
if (s == NULL) return NULL;
if (s == NULL) {
return NULL;
}
memcpy(s + curlen, t, len);
sdssetlen(s, curlen + len);
s[curlen + len] = '\0';
@ -434,7 +467,9 @@ sds sdscatsds(sds s, const sds t) {
sds sdscpylen(sds s, const char *t, size_t len) {
if (sdsalloc(s) < len) {
s = sdsMakeRoomFor(s, len - sdslen(s));
if (s == NULL) return NULL;
if (s == NULL) {
return NULL;
}
}
memcpy(s, t, len);
s[len] = '\0';
@ -468,7 +503,9 @@ int sdsll2str(char *s, long long value) {
*p++ = '0' + (v % 10);
v /= 10;
} while (v);
if (value < 0) *p++ = '-';
if (value < 0) {
*p++ = '-';
}
/* Compute length and add null term. */
l = p - s;
@ -536,7 +573,9 @@ sds sdscatvprintf(sds s, const char *fmt, va_list ap) {
* If not possible we revert to heap allocation. */
if (buflen > sizeof(staticbuf)) {
buf = s_malloc(buflen);
if (buf == NULL) return NULL;
if (buf == NULL) {
return NULL;
}
} else {
buflen = sizeof(staticbuf);
}
@ -549,10 +588,14 @@ sds sdscatvprintf(sds s, const char *fmt, va_list ap) {
vsnprintf(buf, buflen, fmt, cpy);
va_end(cpy);
if (buf[buflen - 2] != '\0') {
if (buf != staticbuf) s_free(buf);
if (buf != staticbuf) {
s_free(buf);
}
buflen *= 2;
buf = s_malloc(buflen);
if (buf == NULL) return NULL;
if (buf == NULL) {
return NULL;
}
continue;
}
break;
@ -560,7 +603,9 @@ sds sdscatvprintf(sds s, const char *fmt, va_list ap) {
/* Finally concat the obtained string to the SDS string and return it. */
t = sdscat(s, buf);
if (buf != staticbuf) s_free(buf);
if (buf != staticbuf) {
s_free(buf);
}
return t;
}
@ -621,7 +666,9 @@ sds sdscatfmt(sds s, char const *fmt, ...) {
/* Make sure there is always space for at least 1 char. */
if (sdsavail(s) == 0) {
s = sdsMakeRoomFor(s, 1);
if (s == NULL) goto fmt_error;
if (s == NULL) {
goto fmt_error;
}
}
switch (*f) {
@ -635,7 +682,9 @@ sds sdscatfmt(sds s, char const *fmt, ...) {
l = (next == 's') ? strlen(str) : sdslen(str);
if (sdsavail(s) < l) {
s = sdsMakeRoomFor(s, l);
if (s == NULL) goto fmt_error;
if (s == NULL) {
goto fmt_error;
}
}
memcpy(s + i, str, l);
sdsinclen(s, l);
@ -643,16 +692,19 @@ sds sdscatfmt(sds s, char const *fmt, ...) {
break;
case 'i':
case 'I':
if (next == 'i')
if (next == 'i') {
num = va_arg(ap, int);
else
} else {
num = va_arg(ap, long long);
}
{
char buf[SDS_LLSTR_SIZE];
l = sdsll2str(buf, num);
if (sdsavail(s) < l) {
s = sdsMakeRoomFor(s, l);
if (s == NULL) goto fmt_error;
if (s == NULL) {
goto fmt_error;
}
}
memcpy(s + i, buf, l);
sdsinclen(s, l);
@ -661,16 +713,19 @@ sds sdscatfmt(sds s, char const *fmt, ...) {
break;
case 'u':
case 'U':
if (next == 'u')
if (next == 'u') {
unum = va_arg(ap, unsigned int);
else
} else {
unum = va_arg(ap, unsigned long long);
}
{
char buf[SDS_LLSTR_SIZE];
l = sdsull2str(buf, unum);
if (sdsavail(s) < l) {
s = sdsMakeRoomFor(s, l);
if (s == NULL) goto fmt_error;
if (s == NULL) {
goto fmt_error;
}
}
memcpy(s + i, buf, l);
sdsinclen(s, l);
@ -721,10 +776,16 @@ sds sdstrim(sds s, const char *cset) {
sp = start = s;
ep = end = s + sdslen(s) - 1;
while(sp <= end && strchr(cset, *sp)) sp++;
while(ep > sp && strchr(cset, *ep)) ep--;
while (sp <= end && strchr(cset, *sp)) {
sp++;
}
while (ep > sp && strchr(cset, *ep)) {
ep--;
}
len = (sp > ep) ? 0 : ((ep - sp) + 1);
if (s != sp) memmove(s, sp, len);
if (s != sp) {
memmove(s, sp, len);
}
s[len] = '\0';
sdssetlen(s, len);
return s;
@ -752,16 +813,24 @@ sds sdstrim(sds s, const char *cset) {
*/
int sdsrange(sds s, ssize_t start, ssize_t end) {
size_t newlen, len = sdslen(s);
if (len > SSIZE_MAX) return -1;
if (len > SSIZE_MAX) {
return -1;
}
if (len == 0) return 0;
if (len == 0) {
return 0;
}
if (start < 0) {
start = len + start;
if (start < 0) start = 0;
if (start < 0) {
start = 0;
}
}
if (end < 0) {
end = len + end;
if (end < 0) end = 0;
if (end < 0) {
end = 0;
}
}
newlen = (start > end) ? 0 : (end - start) + 1;
if (newlen != 0) {
@ -774,7 +843,9 @@ int sdsrange(sds s, ssize_t start, ssize_t end) {
} else {
start = 0;
}
if (start && newlen) memmove(s, s+start, newlen);
if (start && newlen) {
memmove(s, s + start, newlen);
}
s[newlen] = 0;
sdssetlen(s, newlen);
return 0;
@ -784,14 +855,18 @@ int sdsrange(sds s, ssize_t start, ssize_t end) {
void sdstolower(sds s) {
int len = sdslen(s), j;
for (j = 0; j < len; j++) s[j] = tolower(s[j]);
for (j = 0; j < len; j++) {
s[j] = tolower(s[j]);
}
}
/* Apply toupper() to every character of the sds string 's'. */
void sdstoupper(sds s) {
int len = sdslen(s), j;
for (j = 0; j < len; j++) s[j] = toupper(s[j]);
for (j = 0; j < len; j++) {
s[j] = toupper(s[j]);
}
}
/* Compare two sds strings s1 and s2 with memcmp().
@ -813,7 +888,9 @@ int sdscmp(const sds s1, const sds s2) {
l2 = sdslen(s2);
minlen = (l1 < l2) ? l1 : l2;
cmp = memcmp(s1, s2, minlen);
if (cmp == 0) return l1-l2;
if (cmp == 0) {
return l1 - l2;
}
return cmp;
}
@ -837,10 +914,14 @@ sds *sdssplitlen(const char *s, int len, const char *sep, int seplen, int *count
int elements = 0, slots = 5, start = 0, j;
sds *tokens;
if (seplen < 1 || len < 0) return NULL;
if (seplen < 1 || len < 0) {
return NULL;
}
tokens = s_malloc(sizeof(sds) * slots);
if (tokens == NULL) return NULL;
if (tokens == NULL) {
return NULL;
}
if (len == 0) {
*count = 0;
@ -853,13 +934,17 @@ sds *sdssplitlen(const char *s, int len, const char *sep, int seplen, int *count
slots *= 2;
newtokens = s_realloc(tokens, sizeof(sds) * slots);
if (newtokens == NULL) goto cleanup;
if (newtokens == NULL) {
goto cleanup;
}
tokens = newtokens;
}
/* search the separator */
if ((seplen == 1 && *(s + j) == sep[0]) || (memcmp(s + j, sep, seplen) == 0)) {
tokens[elements] = sdsnewlen(s + start, j - start);
if (tokens[elements] == NULL) goto cleanup;
if (tokens[elements] == NULL) {
goto cleanup;
}
elements++;
start = j + seplen;
j = j + seplen - 1; /* skip the separator */
@ -867,15 +952,18 @@ sds *sdssplitlen(const char *s, int len, const char *sep, int seplen, int *count
}
/* Add the final element. We are sure there is room in the tokens array. */
tokens[elements] = sdsnewlen(s + start, len - start);
if (tokens[elements] == NULL) goto cleanup;
if (tokens[elements] == NULL) {
goto cleanup;
}
elements++;
*count = elements;
return tokens;
cleanup:
{
cleanup : {
int i;
for (i = 0; i < elements; i++) sdsfree(tokens[i]);
for (i = 0; i < elements; i++) {
sdsfree(tokens[i]);
}
s_free(tokens);
*count = 0;
return NULL;
@ -884,9 +972,12 @@ cleanup:
/* Free the result returned by sdssplitlen(), or do nothing if 'tokens' is NULL. */
void sdsfreesplitres(sds *tokens, int count) {
if (!tokens) return;
while(count--)
if (!tokens) {
return;
}
while (count--) {
sdsfree(tokens[count]);
}
s_free(tokens);
}
@ -904,16 +995,27 @@ sds sdscatrepr(sds s, const char *p, size_t len) {
case '"':
s = sdscatprintf(s, "\\%c", *p);
break;
case '\n': s = sdscatlen(s,"\\n",2); break;
case '\r': s = sdscatlen(s,"\\r",2); break;
case '\t': s = sdscatlen(s,"\\t",2); break;
case '\a': s = sdscatlen(s,"\\a",2); break;
case '\b': s = sdscatlen(s,"\\b",2); break;
case '\n':
s = sdscatlen(s, "\\n", 2);
break;
case '\r':
s = sdscatlen(s, "\\r", 2);
break;
case '\t':
s = sdscatlen(s, "\\t", 2);
break;
case '\a':
s = sdscatlen(s, "\\a", 2);
break;
case '\b':
s = sdscatlen(s, "\\b", 2);
break;
default:
if (isprint(*p))
if (isprint(*p)) {
s = sdscatprintf(s, "%c", *p);
else
} else {
s = sdscatprintf(s, "\\x%02x", (unsigned char)*p);
}
break;
}
p++;
@ -925,23 +1027,46 @@ sds sdscatrepr(sds s, const char *p, size_t len) {
* integer from 0 to 15 */
int hex_digit_to_int(char c) {
switch (c) {
case '0': return 0;
case '1': return 1;
case '2': return 2;
case '3': return 3;
case '4': return 4;
case '5': return 5;
case '6': return 6;
case '7': return 7;
case '8': return 8;
case '9': return 9;
case 'a': case 'A': return 10;
case 'b': case 'B': return 11;
case 'c': case 'C': return 12;
case 'd': case 'D': return 13;
case 'e': case 'E': return 14;
case 'f': case 'F': return 15;
default: return 0;
case '0':
return 0;
case '1':
return 1;
case '2':
return 2;
case '3':
return 3;
case '4':
return 4;
case '5':
return 5;
case '6':
return 6;
case '7':
return 7;
case '8':
return 8;
case '9':
return 9;
case 'a':
case 'A':
return 10;
case 'b':
case 'B':
return 11;
case 'c':
case 'C':
return 12;
case 'd':
case 'D':
return 13;
case 'e':
case 'E':
return 14;
case 'f':
case 'F':
return 15;
default:
return 0;
}
}
@ -972,24 +1097,24 @@ sds *sdssplitargs(const char *line, int *argc) {
*argc = 0;
while (1) {
/* skip blanks */
while(*p && isspace(*p)) p++;
while (*p && isspace(*p)) {
p++;
}
if (*p) {
/* get a token */
int inq = 0; /* set to 1 if we are in "quotes" */
int insq = 0; /* set to 1 if we are in 'single quotes' */
int done = 0;
if (current == NULL) current = sdsempty();
if (current == NULL) {
current = sdsempty();
}
while (!done) {
if (inq) {
if (*p == '\\' && *(p+1) == 'x' &&
isxdigit(*(p+2)) &&
isxdigit(*(p+3)))
{
if (*p == '\\' && *(p + 1) == 'x' && isxdigit(*(p + 2)) && isxdigit(*(p + 3))) {
unsigned char byte;
byte = (hex_digit_to_int(*(p+2))*16)+
hex_digit_to_int(*(p+3));
byte = (hex_digit_to_int(*(p + 2)) * 16) + hex_digit_to_int(*(p + 3));
current = sdscatlen(current, (char *)&byte, 1);
p += 3;
} else if (*p == '\\' && *(p + 1)) {
@ -997,18 +1122,32 @@ sds *sdssplitargs(const char *line, int *argc) {
p++;
switch (*p) {
case 'n': c = '\n'; break;
case 'r': c = '\r'; break;
case 't': c = '\t'; break;
case 'b': c = '\b'; break;
case 'a': c = '\a'; break;
default: c = *p; break;
case 'n':
c = '\n';
break;
case 'r':
c = '\r';
break;
case 't':
c = '\t';
break;
case 'b':
c = '\b';
break;
case 'a':
c = '\a';
break;
default:
c = *p;
break;
}
current = sdscatlen(current, &c, 1);
} else if (*p == '"') {
/* closing quote must be followed by a space or
* nothing at all. */
if (*(p+1) && !isspace(*(p+1))) goto err;
if (*(p + 1) && !isspace(*(p + 1))) {
goto err;
}
done = 1;
} else if (!*p) {
/* unterminated quotes */
@ -1023,7 +1162,9 @@ sds *sdssplitargs(const char *line, int *argc) {
} else if (*p == '\'') {
/* closing quote must be followed by a space or
* nothing at all. */
if (*(p+1) && !isspace(*(p+1))) goto err;
if (*(p + 1) && !isspace(*(p + 1))) {
goto err;
}
done = 1;
} else if (!*p) {
/* unterminated quotes */
@ -1051,7 +1192,9 @@ sds *sdssplitargs(const char *line, int *argc) {
break;
}
}
if (*p) p++;
if (*p) {
p++;
}
}
/* add the token to the vector */
{
@ -1068,16 +1211,21 @@ sds *sdssplitargs(const char *line, int *argc) {
}
} else {
/* Even on empty input string return something not NULL. */
if (vector == NULL) vector = s_malloc(sizeof(void*));
if (vector == NULL) {
vector = s_malloc(sizeof(void *));
}
return vector;
}
}
err:
while((*argc)--)
while ((*argc)--) {
sdsfree(vector[*argc]);
}
s_free(vector);
if (current) sdsfree(current);
if (current) {
sdsfree(current);
}
*argc = 0;
return NULL;
}
@ -1113,7 +1261,9 @@ sds sdsjoin(char **argv, int argc, char *sep) {
for (j = 0; j < argc; j++) {
join = sdscat(join, argv[j]);
if (j != argc-1) join = sdscat(join,sep);
if (j != argc - 1) {
join = sdscat(join, sep);
}
}
return join;
}
@ -1125,7 +1275,9 @@ sds sdsjoinsds(sds *argv, int argc, const char *sep, size_t seplen) {
for (j = 0; j < argc; j++) {
join = sdscatsds(join, argv[j]);
if (j != argc-1) join = sdscatlen(join,sep,seplen);
if (j != argc - 1) {
join = sdscatlen(join, sep, seplen);
}
}
return join;
}
@ -1135,9 +1287,15 @@ sds sdsjoinsds(sds *argv, int argc, const char *sep, size_t seplen) {
* the overhead of function calls. Here we define these wrappers only for
* the programs SDS is linked to, if they want to touch the SDS internals
* even if they use a different allocator. */
void *sds_malloc(size_t size) { return s_malloc(size); }
void *sds_realloc(void *ptr, size_t size) { return s_realloc(ptr,size); }
void sds_free(void *ptr) { s_free(ptr); }
void *sds_malloc(size_t size) {
return s_malloc(size);
}
void *sds_realloc(void *ptr, size_t size) {
return s_realloc(ptr, size);
}
void sds_free(void *ptr) {
s_free(ptr);
}
#if defined(SDS_TEST_MAIN)
#include <stdio.h>
@ -1149,100 +1307,86 @@ int sdsTest(void) {
{
sds x = sdsnew("foo"), y;
test_cond("Create a string and obtain the length",
sdslen(x) == 3 && memcmp(x,"foo\0",4) == 0)
test_cond("Create a string and obtain the length", sdslen(x) == 3 && memcmp(x, "foo\0", 4) == 0)
sdsfree(x);
x = sdsnewlen("foo", 2);
test_cond("Create a string with specified length",
sdslen(x) == 2 && memcmp(x,"fo\0",3) == 0)
test_cond("Create a string with specified length", sdslen(x) == 2 && memcmp(x, "fo\0", 3) == 0)
x = sdscat(x, "bar");
test_cond("Strings concatenation",
sdslen(x) == 5 && memcmp(x,"fobar\0",6) == 0);
test_cond("Strings concatenation", sdslen(x) == 5 && memcmp(x, "fobar\0", 6) == 0);
x = sdscpy(x, "a");
test_cond("sdscpy() against an originally longer string",
sdslen(x) == 1 && memcmp(x,"a\0",2) == 0)
test_cond("sdscpy() against an originally longer string", sdslen(x) == 1 && memcmp(x, "a\0", 2) == 0)
x = sdscpy(x, "xyzxxxxxxxxxxyyyyyyyyyykkkkkkkkkk");
test_cond("sdscpy() against an originally shorter string",
sdslen(x) == 33 &&
memcmp(x,"xyzxxxxxxxxxxyyyyyyyyyykkkkkkkkkk\0",33) == 0)
sdslen(x) == 33 && memcmp(x, "xyzxxxxxxxxxxyyyyyyyyyykkkkkkkkkk\0", 33) == 0)
sdsfree(x);
x = sdscatprintf(sdsempty(), "%d", 123);
test_cond("sdscatprintf() seems working in the base case",
sdslen(x) == 3 && memcmp(x,"123\0",4) == 0)
test_cond("sdscatprintf() seems working in the base case", sdslen(x) == 3 && memcmp(x, "123\0", 4) == 0)
sdsfree(x);
x = sdsnew("--");
x = sdscatfmt(x, "Hello %s World %I,%I--", "Hi!", LLONG_MIN, LLONG_MAX);
test_cond("sdscatfmt() seems working in the base case",
sdslen(x) == 60 &&
memcmp(x,"--Hello Hi! World -9223372036854775808,"
"9223372036854775807--",60) == 0)
printf("[%s]\n",x);
sdslen(x) == 60
&& memcmp(x,
"--Hello Hi! World -9223372036854775808,"
"9223372036854775807--",
60)
== 0) printf("[%s]\n", x);
sdsfree(x);
x = sdsnew("--");
x = sdscatfmt(x, "%u,%U--", UINT_MAX, ULLONG_MAX);
test_cond("sdscatfmt() seems working with unsigned numbers",
sdslen(x) == 35 &&
memcmp(x,"--4294967295,18446744073709551615--",35) == 0)
sdslen(x) == 35 && memcmp(x, "--4294967295,18446744073709551615--", 35) == 0)
sdsfree(x);
x = sdsnew(" x ");
sdstrim(x, " x");
test_cond("sdstrim() works when all chars match",
sdslen(x) == 0)
test_cond("sdstrim() works when all chars match", sdslen(x) == 0)
sdsfree(x);
x = sdsnew(" x ");
sdstrim(x, " ");
test_cond("sdstrim() works when a single char remains",
sdslen(x) == 1 && x[0] == 'x')
test_cond("sdstrim() works when a single char remains", sdslen(x) == 1 && x[0] == 'x')
sdsfree(x);
x = sdsnew("xxciaoyyy");
sdstrim(x, "xy");
test_cond("sdstrim() correctly trims characters",
sdslen(x) == 4 && memcmp(x,"ciao\0",5) == 0)
test_cond("sdstrim() correctly trims characters", sdslen(x) == 4 && memcmp(x, "ciao\0", 5) == 0)
y = sdsdup(x);
sdsrange(y, 1, 1);
test_cond("sdsrange(...,1,1)",
sdslen(y) == 1 && memcmp(y,"i\0",2) == 0)
test_cond("sdsrange(...,1,1)", sdslen(y) == 1 && memcmp(y, "i\0", 2) == 0)
sdsfree(y);
y = sdsdup(x);
sdsrange(y, 1, -1);
test_cond("sdsrange(...,1,-1)",
sdslen(y) == 3 && memcmp(y,"iao\0",4) == 0)
test_cond("sdsrange(...,1,-1)", sdslen(y) == 3 && memcmp(y, "iao\0", 4) == 0)
sdsfree(y);
y = sdsdup(x);
sdsrange(y, -2, -1);
test_cond("sdsrange(...,-2,-1)",
sdslen(y) == 2 && memcmp(y,"ao\0",3) == 0)
test_cond("sdsrange(...,-2,-1)", sdslen(y) == 2 && memcmp(y, "ao\0", 3) == 0)
sdsfree(y);
y = sdsdup(x);
sdsrange(y, 2, 1);
test_cond("sdsrange(...,2,1)",
sdslen(y) == 0 && memcmp(y,"\0",1) == 0)
test_cond("sdsrange(...,2,1)", sdslen(y) == 0 && memcmp(y, "\0", 1) == 0)
sdsfree(y);
y = sdsdup(x);
sdsrange(y, 1, 100);
test_cond("sdsrange(...,1,100)",
sdslen(y) == 3 && memcmp(y,"iao\0",4) == 0)
test_cond("sdsrange(...,1,100)", sdslen(y) == 3 && memcmp(y, "iao\0", 4) == 0)
sdsfree(y);
y = sdsdup(x);
sdsrange(y, 100, 100);
test_cond("sdsrange(...,100,100)",
sdslen(y) == 0 && memcmp(y,"\0",1) == 0)
test_cond("sdsrange(...,100,100)", sdslen(y) == 0 && memcmp(y, "\0", 1) == 0)
sdsfree(y);
sdsfree(x);
@ -1266,8 +1410,7 @@ int sdsTest(void) {
sdsfree(x);
x = sdsnewlen("\a\n\0foo\r", 7);
y = sdscatrepr(sdsempty(), x, sdslen(x));
test_cond("sdscatrepr(...data...)",
memcmp(y,"\"\\a\\n\\x00foo\\r\"",15) == 0)
test_cond("sdscatrepr(...data...)", memcmp(y, "\"\\a\\n\\x00foo\\r\"", 15) == 0)
{
unsigned int oldfree;
@ -1298,14 +1441,17 @@ int sdsTest(void) {
sdsIncrLen(x, step);
}
test_cond("sdsMakeRoomFor() content",
memcmp("0ABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJ",x,101) == 0);
memcmp("0ABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGH"
"IJABCDEFGHIJ",
x,
101)
== 0);
test_cond("sdsMakeRoomFor() final length", sdslen(x) == 101);
sdsfree(x);
}
}
test_report()
return 0;
test_report() return 0;
}
#endif

File diff suppressed because it is too large Load Diff

View File

@ -229,10 +229,8 @@ static void checkMultiInfo(void) {
pReq->errCode = 0;
}
uv_fs_fdatasync(get_task_manager(),
&pReq->uvFsDataSync,
(uv_file)pReq->uvFsOpen.result,
uvFsDataSyncCb);
uv_fs_fdatasync(
get_task_manager(), &pReq->uvFsDataSync, (uv_file)pReq->uvFsOpen.result, uvFsDataSyncCb);
} else if (pReq->type == INET_HTTP_WEBSERVICE_POST) {
if (pMsg->data.result != CURLE_OK) {
if (pReq->onRspCb && pReq->isCancel == FALSE) {
@ -402,13 +400,8 @@ static size_t writeDataCb(void *pData, size_t size, size_t nmemb, void *pParams)
pReq->uvFsBuf = uv_buf_init(pData, iMemSize);
wr = uv_fs_write(get_task_manager(),
&pReq->uvFsWrite,
(uv_file)pReq->uvFsOpen.result,
&pReq->uvFsBuf,
1,
-1,
NULL);
wr = uv_fs_write(
get_task_manager(), &pReq->uvFsWrite, (uv_file)pReq->uvFsOpen.result, &pReq->uvFsBuf, 1, -1, NULL);
if (wr > 0) {
pReq->dlSize += wr;
@ -440,10 +433,8 @@ static int progressCb(void *pData, double total, double now, double UNUSED(ulTot
if (pParams->onPrgCb) {
if (pParams->type == INET_HTTP_DOWNLOAD_FILE) {
pParams->onPrgCb(pParams->pReqUrl,
pParams->pTaskUuid,
(unsigned char)(now * 100.0 / total),
pParams->pData);
pParams->onPrgCb(
pParams->pReqUrl, pParams->pTaskUuid, (unsigned char)(now * 100.0 / total), pParams->pData);
}
}
@ -554,8 +545,11 @@ static void onDlTimeoutCb(uv_timer_t *UNUSED(pufTimer)) {
}
}
const char *inet_download_file_async(const char *pURL, const char *pPath, on_http_response onRespCb,
on_progress_changed onProgressCb, void *pData) {
const char *inet_download_file_async(const char *pURL,
const char *pPath,
on_http_response onRespCb,
on_progress_changed onProgressCb,
void *pData) {
CURLMcode ret;
uuid_t msgId;
char strMsgId[64];
@ -614,12 +608,8 @@ const char *inet_download_file_async(const char *pURL, const char *pPath, on_htt
dzlog_debug("[%s]: File %s used temp path %s\n", pParams->pTaskUuid, pParams->sPath, pParams->sDlPath);
uv_fs_open(get_task_manager(),
&pParams->uvFsOpen,
pParams->sDlPath,
O_RDWR | O_CREAT | O_TRUNC,
S_IRUSR | S_IWUSR,
NULL);
uv_fs_open(
get_task_manager(), &pParams->uvFsOpen, pParams->sDlPath, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR, NULL);
curl_easy_setopt(pCurl, CURLOPT_WRITEFUNCTION, writeDataCb);
curl_easy_setopt(pCurl, CURLOPT_WRITEDATA, pParams);