Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cmp_tool
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dominik Loidolt
cmp_tool
Commits
c6e72011
Commit
c6e72011
authored
2 years ago
by
Dominik Loidolt
Browse files
Options
Downloads
Patches
Plain Diff
use ARRAY_SIZE macro
parent
7e54813d
No related branches found
No related tags found
1 merge request
!26
Adapt cmp_tool to the chunk decompression
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/compiler.h
+9
-0
9 additions, 0 deletions
include/compiler.h
lib/cmp_io.c
+6
-3
6 additions, 3 deletions
lib/cmp_io.c
with
15 additions
and
3 deletions
include/compiler.h
+
9
−
0
View file @
c6e72011
...
...
@@ -35,6 +35,15 @@
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
/**
*
* ARRAY_SIZE - get the number of elements in a visible array
* @param x the array whose size you want
*
* This does not work on pointers, or arrays declared as [], or
* function parameters. With correct compiler support, such usage
* will cause a build error
*/
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
...
...
This diff is collapsed.
Click to expand it.
lib/cmp_io.c
+
6
−
3
View file @
c6e72011
...
...
@@ -25,7 +25,10 @@
#include
<ctype.h>
#include
<sys/stat.h>
#include
<cmp_tool-config.h>
#include
<compiler.h>
#include
<cmp_io.h>
#include
<cmp_support.h>
#include
<rdcu_cmd.h>
...
...
@@ -416,7 +419,7 @@ enum cmp_data_type string2data_type(const char *data_type_str)
if
(
isalpha
(
data_type_str
[
0
]))
{
/* check if mode is given as text */
size_t
j
;
for
(
j
=
0
;
j
<
sizeof
(
data_type_string_table
)
/
sizeof
(
data_type_string_table
[
0
]
);
j
++
)
{
for
(
j
=
0
;
j
<
ARRAY_SIZE
(
data_type_string_table
);
j
++
)
{
if
(
!
strcmp
(
data_type_str
,
data_type_string_table
[
j
].
str
))
{
data_type
=
data_type_string_table
[
j
].
data_type
;
break
;
...
...
@@ -449,7 +452,7 @@ const char *data_type2string(enum cmp_data_type data_type)
size_t
j
;
const
char
*
string
=
"DATA_TYPE_UNKNOWN"
;
for
(
j
=
0
;
j
<
sizeof
(
data_type_string_table
)
/
sizeof
(
data_type_string_table
[
0
]
);
j
++
)
{
for
(
j
=
0
;
j
<
ARRAY_SIZE
(
data_type_string_table
);
j
++
)
{
if
(
data_type
==
data_type_string_table
[
j
].
data_type
)
{
string
=
data_type_string_table
[
j
].
str
;
break
;
...
...
@@ -495,7 +498,7 @@ int cmp_mode_parse(const char *cmp_mode_str, enum cmp_mode *cmp_mode)
return
-
1
;
if
(
isalpha
(
cmp_mode_str
[
0
]))
{
/* check if mode is given as text */
for
(
j
=
0
;
j
<
sizeof
(
conversion
)
/
sizeof
(
conversion
[
0
]
);
++
j
)
{
for
(
j
=
0
;
j
<
ARRAY_SIZE
(
conversion
);
j
++
)
{
if
(
!
strcmp
(
cmp_mode_str
,
conversion
[
j
].
str
))
{
*
cmp_mode
=
conversion
[
j
].
cmp_mode
;
return
0
;
...
...
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