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.
This commit is contained in:
@@ -200,3 +200,10 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(char *, string_free_erase);
|
||||
#define _cleanup_string_free_erase_ _cleanup_(string_free_erasep)
|
||||
|
||||
bool string_is_safe(const char *p) _pure_;
|
||||
|
||||
static inline size_t strlen_ptr(const char *s) {
|
||||
if (!s)
|
||||
return 0;
|
||||
|
||||
return strlen(s);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user