Skip to content
Snippets Groups Projects
Unverified Commit ea4d51cd authored by Dmitriy A. Gerasimov's avatar Dmitriy A. Gerasimov Committed by GitHub
Browse files

Merge pull request #48 from kelvinblockchain/feature-2298

added dap_strlen(). String may be nullable.
parents 6bfb5f20 5efd8b29
No related branches found
No related tags found
No related merge requests found
......@@ -23,6 +23,26 @@ char *strndup(char *str, int len) {
}
#endif
/**
* dap_strlen:
* @a_str: (nullable): the string
*
* If @a_str is %NULL it returns 0
*
* Returns: length of the string
*/
size_t dap_strlen(const char *a_str)
{
size_t l_length = 0;
if(a_str) {
l_length = strlen(a_str);
}
else
return l_length;
}
/**
* dap_strdup:
* @a_str: (nullable): the string to duplicate
......
......@@ -11,27 +11,28 @@
#include <stdlib.h>
#include <time.h>
#define dap_return_if_fail(expr) {if(!(expr)) {return;}}
#define dap_return_val_if_fail(expr,val) {if(!(expr)) {return (val);}}
#define dap_return_if_fail(expr) {if(!(expr)) {return;}}
#define dap_return_val_if_fail(expr,val) {if(!(expr)) {return (val);}}
#define POINTER_TO_INT(p) ((int) (p))
#define POINTER_TO_UINT(p) ((unsigned int) (p))
#define POINTER_TO_INT(p) ((int) (p))
#define POINTER_TO_UINT(p) ((unsigned int) (p))
#define INT_TO_POINTER(i) ((void*) (i))
#define UINT_TO_POINTER(u) ((void*) (u))
#define INT_TO_POINTER(i) ((void*) (i))
#define UINT_TO_POINTER(u) ((void*) (u))
#undef max
#undef max
#define max(a, b) (((a) > (b)) ? (a) : (b))
#undef min
#undef min
#define min(a, b) (((a) < (b)) ? (a) : (b))
#undef abs
#define abs(a) (((a) < 0) ? -(a) : (a))
#undef abs
#define abs(a) (((a) < 0) ? -(a) : (a))
#undef clamp
#undef clamp
#define clamp(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
size_t dap_strlen(const char *a_str);
char* dap_strdup(const char *a_str);
char* dap_strdup_vprintf(const char *a_format, va_list a_args);
char* dap_strdup_printf(const char *a_format, ...);
......@@ -54,7 +55,7 @@ char* dap_strchug(char *a_string);
// removes trailing spaces
char* dap_strchomp(char *a_string);
// removes leading & trailing spaces
#define dap_strstrip( a_string ) dap_strchomp (dap_strchug (a_string))
#define dap_strstrip( a_string ) dap_strchomp (dap_strchug (a_string))
// Converts all lower case ASCII letters to upper case ASCII letters.
char* dap_strup(const char *a_str, ssize_t a_len);
......
......@@ -106,6 +106,10 @@ size_t dap_enc_decode_out_size(dap_enc_key_t* a_key, const size_t a_buf_in_size,
size_t dap_enc_code(struct dap_enc_key * a_key,const void * a_buf_in,const size_t a_buf_size,
void * a_buf_out, const size_t a_buf_out_size_max, dap_enc_data_type_t a_data_type_out)
{
if(!a_key) {
log_it(L_ERROR, "key in dap_enc_code() is NULL");
return 0;
}
if(a_key->enc_na) {
if(a_data_type_out == DAP_ENC_DATA_TYPE_RAW) {
return a_key->enc_na(a_key, a_buf_in, a_buf_size, a_buf_out, a_buf_out_size_max);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment