Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
libdap
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
cellframe
libdap
Commits
cf6927f5
Commit
cf6927f5
authored
5 years ago
by
alexander.lysikov
Browse files
Options
Downloads
Patches
Plain Diff
added dap_strcmp() and dap_strncmp() for nullable strings
parent
b86ad74b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/dap_strfuncs.c
+51
-23
51 additions, 23 deletions
core/dap_strfuncs.c
core/dap_strfuncs.h
+5
-1
5 additions, 1 deletion
core/dap_strfuncs.h
with
56 additions
and
24 deletions
core/dap_strfuncs.c
+
51
−
23
View file @
cf6927f5
...
...
@@ -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:
...
...
This diff is collapsed.
Click to expand it.
core/dap_strfuncs.h
+
5
−
1
View file @
cf6927f5
...
...
@@ -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
);
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment