From: Thomas Weißschuh Date: Mon, 13 May 2024 08:46:31 +0000 (+0200) Subject: lib/path: use _read_buffer for _read_string() X-Git-Tag: v2.42-start~345 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d4fc7055ca11fad8f7664c5f28ef6c9622acb166;p=thirdparty%2Futil-linux.git lib/path: use _read_buffer for _read_string() ul_path_read_buffer already provides zero-termination and newline trimming, so make use of it. Signed-off-by: Thomas Weißschuh --- diff --git a/lib/path.c b/lib/path.c index 7a1d03c76..6381cc5d8 100644 --- a/lib/path.c +++ b/lib/path.c @@ -659,17 +659,11 @@ int ul_path_read_string(struct path_cxt *pc, char **str, const char *path) return -EINVAL; *str = NULL; - rc = ul_path_read(pc, buf, sizeof(buf) - 1, path); + + rc = ul_path_read_buffer(pc, buf, sizeof(buf), path); if (rc < 0) return rc; - /* Remove trailing newline (usual in sysfs) */ - if (rc > 0 && *(buf + rc - 1) == '\n') - --rc; - if (rc == 0) - return 0; - - buf[rc] = '\0'; *str = strdup(buf); if (!*str) rc = -ENOMEM;