| 1234567891011121314151617181920212223242526272829303132333435363738 |
- #include "toolbox/cstring.h"
- #include "toolbox/log.h"
- #include <stdbool.h>
- #include <stddef.h>
- #include <stdlib.h>
- #define TEST_FOR_NULL(POINTER) \
- if ( POINTER == NULL ) \
- { \
- LOG_ERROR("Null Pointer Not Expected"); \
- exit(EXIT_FAILURE); \
- }
- size_t
- cstring_len(const char *p_cstr) {
- TEST_FOR_NULL(p_cstr);
- size_t len = 0;
- while ( *(p_cstr + len++) ) {}
- return --len;
- }
- bool
- cstring_equal(const char *restrict p_cstr1, const char *restrict p_cstr2) {
- const size_t cstr1_size = cstring_len(p_cstr1);
- const size_t cstr2_size = cstring_len(p_cstr2);
- if ( cstr1_size != cstr2_size ) {
- return false;
- }
- for ( size_t i = 0; i < cstr1_size; ++i ) {
- if ( p_cstr1[i] != p_cstr2[i] ) {
- return false;
- }
- }
- return true;
- }
- #undef TEST_FOR_NULL
|