comparison toys/posix/ls.c @ 885:beb32d780164

Add library function for the file permission formatting in ls and stat
author Felix Janda <felix.janda@posteo.de>
date Mon, 22 Apr 2013 22:29:43 +0200
parents 017b8fd3c9ac
children b92cb3cc9696
comparison
equal deleted inserted replaced
884:ac9991f66d0d 885:beb32d780164
333 if (flags & FLAG_i) xprintf("% *lu ", len[1], (unsigned long)st->st_ino); 333 if (flags & FLAG_i) xprintf("% *lu ", len[1], (unsigned long)st->st_ino);
334 if (flags & FLAG_s) xprintf("% *lu ", len[6], (unsigned long)st->st_blocks); 334 if (flags & FLAG_s) xprintf("% *lu ", len[6], (unsigned long)st->st_blocks);
335 335
336 if (flags & (FLAG_l|FLAG_o|FLAG_n|FLAG_g)) { 336 if (flags & (FLAG_l|FLAG_o|FLAG_n|FLAG_g)) {
337 struct tm *tm; 337 struct tm *tm;
338 char perm[11], thyme[64], c, d, *usr, *upad, *grp, *grpad; 338 char perm[11], thyme[64], *usr, *upad, *grp, *grpad;
339 int i, bit; 339
340 340 format_mode(&perm, mode);
341 perm[10]=0;
342 for (i=0; i<9; i++) {
343 bit = mode & (1<<i);
344 c = i%3;
345 if (!c && (mode & (1<<((d=i/3)+9)))) {
346 c = "tss"[d];
347 if (!bit) c &= ~0x20;
348 } else c = bit ? "xwr"[c] : '-';
349 perm[9-i] = c;
350 }
351
352 if (S_ISDIR(mode)) c = 'd';
353 else if (S_ISBLK(mode)) c = 'b';
354 else if (S_ISCHR(mode)) c = 'c';
355 else if (S_ISLNK(mode)) c = 'l';
356 else if (S_ISFIFO(mode)) c = 'p';
357 else if (S_ISSOCK(mode)) c = 's';
358 else c = '-';
359 *perm = c;
360 341
361 tm = localtime(&(st->st_mtime)); 342 tm = localtime(&(st->st_mtime));
362 strftime(thyme, sizeof(thyme), "%F %H:%M", tm); 343 strftime(thyme, sizeof(thyme), "%F %H:%M", tm);
363 344
364 if (flags&FLAG_o) grp = grpad = toybuf+256; 345 if (flags&FLAG_o) grp = grpad = toybuf+256;