Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
ccan
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mirror
ccan
Commits
299170fa
Commit
299170fa
authored
Oct 15, 2015
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mem: add memeqzero.
Signed-off-by:
Rusty Russell
<
rusty@rustcorp.com.au
>
parent
78abb537
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
1 deletion
+31
-1
ccan/mem/mem.c
ccan/mem/mem.c
+13
-0
ccan/mem/mem.h
ccan/mem/mem.h
+13
-0
ccan/mem/test/api.c
ccan/mem/test/api.c
+5
-1
No files found.
ccan/mem/mem.c
View file @
299170fa
...
...
@@ -88,3 +88,16 @@ void memswap(void *a, void *b, size_t n)
n
-=
m
;
}
}
bool
memeqzero
(
const
void
*
data
,
size_t
length
)
{
const
unsigned
char
*
p
=
data
;
while
(
length
)
{
if
(
*
p
)
return
false
;
p
++
;
length
--
;
}
return
true
;
}
ccan/mem/mem.h
View file @
299170fa
...
...
@@ -144,6 +144,19 @@ static inline bool memstarts(void const *data, size_t data_len,
* }
*/
PURE_FUNCTION
bool
memeqzero
(
const
void
*
data
,
size_t
length
);
/**
* memeqzero - Is a byte array all zeroes?
* @data: byte array
* @length: length of @data in bytes
*
* Example:
* if (memeqzero(somebytes, bytes_len)) {
* printf("somebytes == 0!\n");
* }
*/
PURE_FUNCTION
static
inline
bool
memeqstr
(
const
void
*
data
,
size_t
length
,
const
char
*
string
)
{
return
memeq
(
data
,
length
,
string
,
strlen
(
string
));
...
...
ccan/mem/test/api.c
View file @
299170fa
...
...
@@ -18,7 +18,7 @@ int main(void)
char
tmp1
[
SWAPSIZE
],
tmp2
[
SWAPSIZE
];
/* This is how many tests you plan to run */
plan_tests
(
6
2
);
plan_tests
(
6
5
);
ok1
(
memmem
(
haystack1
,
sizeof
(
haystack1
),
needle1
,
2
)
==
haystack1
);
ok1
(
memmem
(
haystack1
,
sizeof
(
haystack1
),
needle1
,
3
)
==
NULL
);
...
...
@@ -113,6 +113,10 @@ int main(void)
ok1
(
memcmp
(
tmp1
,
haystack2
,
sizeof
(
haystack2
))
==
0
);
ok1
(
memcmp
(
tmp2
,
haystack1
,
sizeof
(
haystack1
))
==
0
);
ok1
(
memeqzero
(
NULL
,
0
));
ok1
(
memeqzero
(
scan2
,
3
));
ok1
(
!
memeqzero
(
scan2
,
4
));
/* This exits depending on whether all tests passed */
return
exit_status
();
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment