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

Merge pull request #52 from kelvinblockchain/feature-2302

Feature 2302
parents b86ad74b f628feaf
No related branches found
No related tags found
1 merge request!24Support 3689
......@@ -8,7 +8,6 @@
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <errno.h>
#include "dap_common.h"
......@@ -23,7 +22,6 @@ char *strndup(char *str, int len) {
}
#endif
/**
* dap_strlen:
* @a_str: (nullable): the string
......@@ -42,6 +40,36 @@ size_t dap_strlen(const char *a_str)
return l_length;
}
/**
* dap_strcmp:
* @a_str1: (nullable): the string
* @a_str2: (nullable): the string
*
* Compare a_str1 and a_str2
*/
int dap_strcmp(const char *a_str1, const char *a_str2)
{
if(a_str1 && a_str2) {
return strcmp(a_str1, a_str2);
}
return -1;
}
/**
* dap_strcmp:
* @a_str1: (nullable): the string
* @a_str2: (nullable): the string
*
* Compare a_n characters of a_str1 and a_str2
*/
int dap_strncmp(const char *a_str1, const char *a_str2, size_t a_n)
{
if(a_str1 && a_str2) {
return strncmp(a_str1, a_str2, a_n);
}
return -1;
}
/**
* dap_strdup:
* @a_str: (nullable): the string to duplicate
......@@ -115,27 +143,27 @@ char* dap_strdup_printf(const char *a_format, ...)
}
/*
// alternative version
char* dap_strdup_printf2(const char *a_format, ...)
{
size_t l_buffer_size = 0;
char *l_buffer = NULL;
va_list l_args;
va_start(l_args, a_format);
l_buffer_size += vsnprintf(l_buffer, 0, a_format, l_args);
va_end(l_args);
if(!l_buffer_size)
return NULL;
l_buffer = DAP_NEW_SIZE(char, l_buffer_size + 1);
va_start(l_args, a_format);
vsnprintf(l_buffer, l_buffer_size + 1, a_format, l_args);
va_end(l_args);
return l_buffer;
}*/
// alternative version
char* dap_strdup_printf2(const char *a_format, ...)
{
size_t l_buffer_size = 0;
char *l_buffer = NULL;
va_list l_args;
va_start(l_args, a_format);
l_buffer_size += vsnprintf(l_buffer, 0, a_format, l_args);
va_end(l_args);
if(!l_buffer_size)
return NULL;
l_buffer = DAP_NEW_SIZE(char, l_buffer_size + 1);
va_start(l_args, a_format);
vsnprintf(l_buffer, l_buffer_size + 1, a_format, l_args);
va_end(l_args);
return l_buffer;
}*/
/**
* dap_stpcpy:
......
......@@ -33,6 +33,11 @@
#define clamp(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
size_t dap_strlen(const char *a_str);
// compare a_str1 and a_str2
int dap_strcmp(const char *a_str1, const char *a_str2);
// compare a_n characters of a_str1 and a_str2
int dap_strncmp(const char *a_str1, const char *a_str2, size_t a_n);
// duplicates a string
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, ...);
......@@ -66,4 +71,3 @@ char* dap_strreverse(char *a_string);
#define DAP_USEC_PER_SEC 1000000
void dap_usleep(time_t a_microseconds);
......@@ -59,14 +59,14 @@ void dap_str_array_test(void)
const char *l_s_in = "1:23:: Test: :\n:String:";
char **l_s_array = dap_strsplit(l_s_in, ":", -1);
int l_count = 1;
size_t l_count = 1;
char *l_s_tmp = dap_strstr_len(l_s_in, -1, ":");
while(l_s_tmp) {
l_s_tmp = dap_strstr_len(l_s_tmp + 1, -1, ":");
l_count++;
}
char **l_s_array_copy = dap_strdupv(l_s_array);
char **l_s_array_copy = dap_strdupv((const char**)l_s_array);
dap_assert_PIF(dap_str_countv(l_s_array) == l_count, "String split");
dap_assert_PIF(dap_str_countv(l_s_array_copy) == l_count, "String copy");
......
......@@ -15,7 +15,7 @@
int main(void)
{
// switch off debug info from library
set_log_level(L_CRITICAL);
dap_log_level_set(L_CRITICAL);
dap_enc_aes_tests_run();
dap_enc_oaes_tests_run();
dap_enc_base64_tests_run();
......
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