From d4fc7055ca11fad8f7664c5f28ef6c9622acb166 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thomas=20Wei=C3=9Fschuh?= Date: Mon, 13 May 2024 10:46:31 +0200 Subject: [PATCH] lib/path: use _read_buffer for _read_string() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit ul_path_read_buffer already provides zero-termination and newline trimming, so make use of it. Signed-off-by: Thomas Weißschuh --- lib/path.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) 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; -- 2.47.2