diff options
| author | Thomas Weißschuh <thomas@t-8ch.de> | 2024-05-13 10:46:31 +0200 |
|---|---|---|
| committer | Thomas Weißschuh <thomas@t-8ch.de> | 2024-05-13 12:35:48 +0200 |
| commit | d4fc7055ca11fad8f7664c5f28ef6c9622acb166 (patch) | |
| tree | 5893424436641d358ae50b56b79830eef528ecc9 /lib/path.c | |
| parent | 057080b5c89fa63cece8a5d4a6da4959bd004aa1 (diff) | |
| download | util-linux-d4fc7055ca11fad8f7664c5f28ef6c9622acb166.tar.gz | |
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 <thomas@t-8ch.de>
Diffstat (limited to 'lib/path.c')
| -rw-r--r-- | lib/path.c | 10 |
1 files changed, 2 insertions, 8 deletions
diff --git a/lib/path.c b/lib/path.c index 7a1d03c76d..6381cc5d8f 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; |
