From 7bf7ce28b5a1f589f0f2382e54c03ab9b0794fab Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 20 Jul 2017 11:38:15 +0200 Subject: string-util: add strlen_ptr() helper strlen_ptr() is to strlen() what streq_ptr() is to streq(): i.e. it handles NULL strings in a smart way. --- src/test/test-string-util.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/test/test-string-util.c') diff --git a/src/test/test-string-util.c b/src/test/test-string-util.c index 4b3e924cfb..604701ff7a 100644 --- a/src/test/test-string-util.c +++ b/src/test/test-string-util.c @@ -336,6 +336,12 @@ static void test_first_word(void) { assert_se(!first_word("Hellooo", "Hello")); } +static void test_strlen_ptr(void) { + assert_se(strlen_ptr("foo") == 3); + assert_se(strlen_ptr("") == 0); + assert_se(strlen_ptr(NULL) == 0); +} + int main(int argc, char *argv[]) { test_string_erase(); test_ascii_strcasecmp_n(); @@ -358,6 +364,7 @@ int main(int argc, char *argv[]) { test_in_charset(); test_split_pair(); test_first_word(); + test_strlen_ptr(); return 0; } -- cgit v1.2.1