aboutsummaryrefslogtreecommitdiff
path: root/toys/other/blkid.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2016-03-23 03:27:39 -0500
committerRob Landley <rob@landley.net>2016-03-23 03:27:39 -0500
commit5a7b147c18e0550536f888d531dea73696336902 (patch)
tree4eb3ee8d70edcb28013171bf0e8bc4a3b91b1332 /toys/other/blkid.c
parenta8d0d13376251e1ff35a557dddea1d2e3c81a149 (diff)
downloadtoybox-5a7b147c18e0550536f888d531dea73696336902.tar.gz
Minor blkid cleanup. (There was a while(ptr[-1]==' ') ptr--; that could fall
off the start of the string. I pulled on the thread...)
Diffstat (limited to 'toys/other/blkid.c')
-rw-r--r--toys/other/blkid.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/toys/other/blkid.c b/toys/other/blkid.c
index c701c800..04c9b5f0 100644
--- a/toys/other/blkid.c
+++ b/toys/other/blkid.c
@@ -59,13 +59,13 @@ static const struct fstype fstypes[] = {
static void do_blkid(int fd, char *name)
{
- int off, i, j;
+ int off, i, j, len;
char *type;
off = i = 0;
for (;;) {
- int pass = 0, len;
+ int pass = 0;
// Read next block of data
len = readall(fd, toybuf, sizeof(toybuf));
@@ -116,15 +116,14 @@ static void do_blkid(int fd, char *name)
printf("%s:",name);
if (fstypes[i].label_len) {
- int label_len = fstypes[i].label_len, loff = fstypes[i].label_off-off;
- if (!strcmp(fstypes[i].name, "vfat")) {
- if (!strncmp(toybuf+loff, "NO NAME ", label_len))
- label_len=0;
- else while (toybuf[loff+label_len-1] == ' ')
- label_len--;
+ char *s = toybuf+fstypes[i].label_off-off;;
+
+ len = fstypes[i].label_len;
+ if (!strcmp(type, "vfat")) {
+ while (len && s[len-1]==' ') len--;
+ if (strstart(&s, "NO NAME")) len=0;
}
- if (label_len)
- printf(" LABEL=\"%.*s\"", label_len, toybuf+loff);
+ if (len) printf(" LABEL=\"%.*s\"", len, s);
}
if (fstypes[i].uuid_off) {