comparison toys/posix/ls.c @ 941:62ba5ce62e9d 0.4.5

Make ls output major, minor for block devices.
author Rob Landley <rob@landley.net>
date Mon, 01 Jul 2013 00:10:28 -0500
parents a425f97975d3
children 422696039640
comparison
equal deleted inserted replaced
940:a425f97975d3 941:62ba5ce62e9d
113 if (flags & (FLAG_l|FLAG_o|FLAG_n|FLAG_g)) { 113 if (flags & (FLAG_l|FLAG_o|FLAG_n|FLAG_g)) {
114 unsigned fn = flags & FLAG_n; 114 unsigned fn = flags & FLAG_n;
115 len[2] = numlen(st->st_nlink); 115 len[2] = numlen(st->st_nlink);
116 len[3] = strlen(fn ? utoa(st->st_uid) : getusername(st->st_uid)); 116 len[3] = strlen(fn ? utoa(st->st_uid) : getusername(st->st_uid));
117 len[4] = strlen(fn ? utoa(st->st_gid) : getgroupname(st->st_gid)); 117 len[4] = strlen(fn ? utoa(st->st_gid) : getgroupname(st->st_gid));
118 len[5] = numlen(st->st_size); 118 if (S_ISBLK(st->st_mode) || S_ISCHR(st->st_mode)) {
119 // cheating slightly here: assuming minor is always 3 digits to avoid
120 // tracking another column
121 len[5] = numlen(major(st->st_rdev))+5;
122 } else len[5] = numlen(st->st_size);
119 } 123 }
120 if (flags & FLAG_s) *len += (len[6] = numlen(st->st_blocks)); 124 if (flags & FLAG_s) *len += (len[6] = numlen(st->st_blocks));
121 } 125 }
122 126
123 static int compare(void *a, void *b) 127 static int compare(void *a, void *b)
365 utoa_to_buf(st->st_uid, TT.uid_buf, 12); 369 utoa_to_buf(st->st_uid, TT.uid_buf, 12);
366 } else usr = getusername(st->st_uid); 370 } else usr = getusername(st->st_uid);
367 } 371 }
368 372
369 // Coerce the st types into something we know we can print. 373 // Coerce the st types into something we know we can print.
370 xprintf("%s% *ld %s%s%s%s% *"PRId64" %s ", perm, totals[2]+1, 374 printf("%s% *ld %s%s%s%s", perm, totals[2]+1, (long)st->st_nlink,
371 (long)st->st_nlink, usr, upad, grp, grpad, totals[5]+1, 375 usr, upad, grp, grpad);
372 (int64_t)st->st_size, thyme); 376
377 if (S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode))
378 printf("% *d,% 4d", totals[5]-4, major(st->st_rdev),minor(st->st_rdev));
379 else printf("% *"PRId64, totals[5]+1, (int64_t)st->st_size);
380 xprintf(" %s ", thyme);
373 } 381 }
374 382
375 if ((flags & FLAG_color) && TT.screen_width) { 383 if ((flags & FLAG_color) && TT.screen_width) {
376 color = color_from_mode(st->st_mode); 384 color = color_from_mode(st->st_mode);
377 if (color) printf("\033[%d;%dm", color>>8, color&255); 385 if (color) printf("\033[%d;%dm", color>>8, color&255);