diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2020-07-20 02:03:02 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2020-07-20 02:03:02 +0200 |
commit | 2dd82f465e16f9df991d5677114370298a2ffade (patch) | |
tree | bbd5cd4e159a1ce6a2bdb9011aec41c19a40c039 /miscutils | |
parent | 9a2d899273e3a8a58bdb4c3834d65d22658e7821 (diff) | |
download | busybox-2dd82f465e16f9df991d5677114370298a2ffade.tar.gz |
lsscsi: code shrink
function old new delta
lsscsi_main 298 302 +4
get_line 56 45 -11
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 4/-11) Total: -7 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
-rw-r--r-- | miscutils/lsscsi.c | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/miscutils/lsscsi.c b/miscutils/lsscsi.c index f737d33d9..76c281264 100644 --- a/miscutils/lsscsi.c +++ b/miscutils/lsscsi.c @@ -27,25 +27,21 @@ static const char scsi_dir[] ALIGN1 = "/sys/bus/scsi/devices"; -static char *get_line(const char *filename, char *buf, unsigned *bufsize_p) +static char *get_line(const char *filename, char *buf, char *bufend) { - unsigned bufsize = *bufsize_p; - ssize_t sz; + ssize_t sz = bufend - buf - 2; /* -2 for two NULs */ - if ((int)(bufsize - 2) <= 0) + if (sz <= 0) return buf; - sz = open_read_close(filename, buf, bufsize - 2); + sz = open_read_close(filename, buf, sz); if (sz < 0) sz = 0; buf[sz] = '\0'; - sz = (trim(buf) - buf) + 1; - bufsize -= sz; - buf += sz; + buf = trim(buf) + 1; buf[0] = '\0'; - *bufsize_p = bufsize; return buf; } @@ -61,7 +57,6 @@ int lsscsi_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) while ((de = readdir(dir)) != NULL) { char buf[256]; char *ptr; - unsigned bufsize; const char *vendor; const char *type_str; const char *type_name; @@ -76,15 +71,17 @@ int lsscsi_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) if (chdir(de->d_name) != 0) continue; - bufsize = sizeof(buf); vendor = buf; - ptr = get_line("vendor", buf, &bufsize); + ptr = get_line("vendor", buf, buf + sizeof(buf)); + type_str = ptr; - ptr = get_line("type", ptr, &bufsize); + ptr = get_line("type", ptr, buf + sizeof(buf)); + model = ptr; - ptr = get_line("model", ptr, &bufsize); + ptr = get_line("model", ptr, buf + sizeof(buf)); + rev = ptr; - ptr = get_line("rev", ptr, &bufsize); + /*ptr =*/ get_line("rev", ptr, buf + sizeof(buf)); printf("[%s]\t", de->d_name); |