mirror of
https://github.com/cryb-to/cryb-to.git
synced 2025-01-03 02:11:10 +00:00
Add a t_compare_strn() function which is to t_compare_str() what strncmp() is to
strcmp().
This commit is contained in:
parent
d2a98cd870
commit
6eaaac308f
2 changed files with 17 additions and 0 deletions
|
@ -86,6 +86,7 @@ int t_is_null(const void *);
|
||||||
int t_is_not_null(const void *);
|
int t_is_not_null(const void *);
|
||||||
int t_compare_mem(const void *, const void *, size_t);
|
int t_compare_mem(const void *, const void *, size_t);
|
||||||
int t_compare_str(const char *, const char *);
|
int t_compare_str(const char *, const char *);
|
||||||
|
int t_compare_strn(const char *, const char *, size_t);
|
||||||
#define t_compare_num(n, t) int t_compare_##n(t, t);
|
#define t_compare_num(n, t) int t_compare_##n(t, t);
|
||||||
t_compare_num(i, int);
|
t_compare_num(i, int);
|
||||||
t_compare_num(u, unsigned int);
|
t_compare_num(u, unsigned int);
|
||||||
|
|
|
@ -102,6 +102,22 @@ t_compare_str(const char *expected, const char *received)
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Compare two strings up to a specific length, and print a verbose
|
||||||
|
* message if they differ.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
t_compare_strn(const char *expected, const char *received, size_t len)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (strncmp(expected, received, len) != 0) {
|
||||||
|
t_verbose("expected %.*s\n", (int)len, expected);
|
||||||
|
t_verbose("received %.*s\n", (int)len, received);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Compare two numbers, and print a verbose message if they differ.
|
* Compare two numbers, and print a verbose message if they differ.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue