string-util: add new strdupcspn()/strdupspn()
These combine strndup() + strspn()/strcspn() into one. There are a bunch of strndupa() calls that could use similar treatment (or should be converted to strdup[c]spn(), but this commit doesn't bother with that.
This commit is contained in:
@@ -175,15 +175,13 @@ static int image_new(
|
||||
static int extract_pretty(const char *path, const char *suffix, char **ret) {
|
||||
_cleanup_free_ char *name = NULL;
|
||||
const char *p;
|
||||
size_t n;
|
||||
|
||||
assert(path);
|
||||
assert(ret);
|
||||
|
||||
p = last_path_component(path);
|
||||
n = strcspn(p, "/");
|
||||
|
||||
name = strndup(p, n);
|
||||
name = strdupcspn(p, "/");
|
||||
if (!name)
|
||||
return -ENOMEM;
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ static int url_from_catalog(sd_journal *j, char **ret) {
|
||||
weblink += strspn(weblink, " \t");
|
||||
|
||||
/* Cut out till next whitespace/newline */
|
||||
url = strndup(weblink, strcspn(weblink, WHITESPACE));
|
||||
url = strdupcspn(weblink, WHITESPACE);
|
||||
if (!url)
|
||||
return log_oom();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user