aboutsummaryrefslogtreecommitdiff
path: root/lib/sg_lib.c
diff options
context:
space:
mode:
authorDouglas Gilbert <dgilbert@interlog.com>2022-06-27 18:26:54 +0000
committerDouglas Gilbert <dgilbert@interlog.com>2022-06-27 18:26:54 +0000
commit30842a3103045e471ec8169f09135bb6766e5e1d (patch)
treea37d6d0bc773726fff04c163457d3bb22e6efa71 /lib/sg_lib.c
parent2e225c87784735360e9619766efe06782179a86a (diff)
downloadsg3_utils-30842a3103045e471ec8169f09135bb6766e5e1d.tar.gz
more JSON work: sense data and vpd device id, start on sg_vpd
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@956 6180dd3e-e324-4e3e-922d-17de1ae2f315
Diffstat (limited to 'lib/sg_lib.c')
-rw-r--r--lib/sg_lib.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/lib/sg_lib.c b/lib/sg_lib.c
index 418638b5..7256c435 100644
--- a/lib/sg_lib.c
+++ b/lib/sg_lib.c
@@ -2957,11 +2957,11 @@ dStrHexStr(const char * str, int len, const char * leadin, int oformat,
int b_len, char * b)
{
bool want_ascii = (0 == oformat);
- char lf_or = (oformat > 1) ? ' ' : '\n';
int bpstart, bpos, k, n, prior_ascii_len;
char buff[DSHS_LINE_BLEN + 2]; /* allow for trailing null */
char a[DSHS_BPL + 1]; /* printable ASCII bytes or '.' */
const char * p = str;
+ const char * lf_or = (oformat > 1) ? " " : "\n";
if (len <= 0) {
if (b_len > 0)
@@ -2974,16 +2974,20 @@ dStrHexStr(const char * str, int len, const char * leadin, int oformat,
memset(a, ' ', DSHS_BPL);
a[DSHS_BPL] = '\0';
}
+ n = 0;
+ bpstart = 0;
if (leadin) {
- bpstart = strlen(leadin);
- /* Cap leadin at (DSHS_LINE_BLEN - 70) characters */
- if (bpstart > (DSHS_LINE_BLEN - 70))
- bpstart = DSHS_LINE_BLEN - 70;
- } else
- bpstart = 0;
+ if (oformat > 1)
+ n += sg_scnpr(b + n, b_len - n, "%s", leadin);
+ else {
+ bpstart = strlen(leadin);
+ /* Cap leadin at (DSHS_LINE_BLEN - 70) characters */
+ if (bpstart > (DSHS_LINE_BLEN - 70))
+ bpstart = DSHS_LINE_BLEN - 70;
+ }
+ }
bpos = bpstart;
prior_ascii_len = bpstart + (DSHS_BPL * 3) + 1;
- n = 0;
memset(buff, ' ', DSHS_LINE_BLEN);
buff[DSHS_LINE_BLEN] = '\0';
if (bpstart > 0)
@@ -3005,7 +3009,7 @@ dStrHexStr(const char * str, int len, const char * leadin, int oformat,
prior_ascii_len, buff, a);
memset(a, ' ', DSHS_BPL);
} else
- n += sg_scnpr(b + n, b_len - n, "%s%c", buff, lf_or);
+ n += sg_scnpr(b + n, b_len - n, "%s%s", buff, lf_or);
if (n >= (b_len - 1))
goto fini;
memset(buff, ' ', DSHS_LINE_BLEN);
@@ -3021,7 +3025,7 @@ dStrHexStr(const char * str, int len, const char * leadin, int oformat,
n += sg_scnpr(b + n, b_len - n, "%-*s %s\n", prior_ascii_len,
buff, a);
else
- n += sg_scnpr(b + n, b_len - n, "%s%c", buff, lf_or);
+ n += sg_scnpr(b + n, b_len - n, "%s%s", buff, lf_or);
}
fini:
if (oformat > 1)