various: use strdup_to() in various obvious cases

strdup_to() returns 0 on success and here we convert obvious blocks
which either return -ENOMEM or 0.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2024-03-20 15:13:44 +01:00
parent 7e850da3d6
commit 454318d3e8
17 changed files with 31 additions and 124 deletions
+2 -7
View File
@@ -1094,7 +1094,6 @@ int path_extract_filename(const char *path, char **ret) {
}
int path_extract_directory(const char *path, char **ret) {
_cleanup_free_ char *a = NULL;
const char *c, *next = NULL;
int r;
@@ -1118,14 +1117,10 @@ int path_extract_directory(const char *path, char **ret) {
if (*path != '/') /* filename only */
return -EDESTADDRREQ;
a = strdup("/");
if (!a)
return -ENOMEM;
*ret = TAKE_PTR(a);
return 0;
return strdup_to(ret, "/");
}
a = strndup(path, next - path);
_cleanup_free_ char *a = strndup(path, next - path);
if (!a)
return -ENOMEM;