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:
Lennart Poettering
2017-07-31 18:20:28 +02:00
parent 6f8cbcdb27
commit 7bf7ce28b5
8 changed files with 24 additions and 7 deletions
+2 -1
View File
@@ -25,6 +25,7 @@
#include "alloc-util.h"
#include "hexdecoct.h"
#include "macro.h"
#include "string-util.h"
#include "util.h"
char octchar(int x) {
@@ -569,7 +570,7 @@ static int base64_append_width(char **prefix, int plen,
lines = (len + width - 1) / width;
slen = sep ? strlen(sep) : 0;
slen = strlen_ptr(sep);
t = realloc(*prefix, plen + 1 + slen + (indent + width + 1) * lines);
if (!t)
return -ENOMEM;