ls cleanup

This commit is contained in:
Connor Lane Smith 2011-05-27 23:56:43 +01:00
parent 2dfe5c6b8b
commit 0a3a8c55e4
2 changed files with 14 additions and 19 deletions

31
ls.c
View File

@ -150,7 +150,8 @@ mkent(Entry *ent, char *path)
void
output(Entry *ent)
{
char buf[BUFSIZ], mode[11], *fmt;
char buf[BUFSIZ], *fmt;
char mode[] = "----------";
struct group *gr;
struct passwd *pw;
@ -175,24 +176,18 @@ output(Entry *ent)
else
mode[0] = '?';
mode[1] = (ent->mode & S_IRUSR) ? 'r' : '-';
mode[2] = (ent->mode & S_IWUSR) ? 'w' : '-';
if(ent->mode & S_ISUID)
mode[3] = (ent->mode & S_IXUSR) ? 's' : 'S';
else
mode[3] = (ent->mode & S_IXUSR) ? 'x' : '-';
if(ent->mode & S_IRUSR) mode[1] = 'r';
if(ent->mode & S_IWUSR) mode[2] = 'w';
if(ent->mode & S_IXUSR) mode[3] = 'x';
if(ent->mode & S_IRGRP) mode[4] = 'r';
if(ent->mode & S_IWGRP) mode[5] = 'w';
if(ent->mode & S_IXGRP) mode[6] = 'x';
if(ent->mode & S_IROTH) mode[7] = 'r';
if(ent->mode & S_IWOTH) mode[8] = 'w';
if(ent->mode & S_IXOTH) mode[9] = 'x';
mode[4] = (ent->mode & S_IRGRP) ? 'r' : '-';
mode[5] = (ent->mode & S_IWGRP) ? 'w' : '-';
if(ent->mode & S_ISGID)
mode[6] = (ent->mode & S_IXGRP) ? 's' : 'S';
else
mode[6] = (ent->mode & S_IXGRP) ? 'x' : '-';
mode[7] = (ent->mode & S_IROTH) ? 'r' : '-';
mode[8] = (ent->mode & S_IWOTH) ? 'w' : '-';
mode[9] = (ent->mode & S_IXOTH) ? 'x' : '-';
mode[10] = '\0';
if(ent->mode & S_ISUID) mode[3] = (mode[3] == 'x' ? 's' : 'S');
if(ent->mode & S_ISGID) mode[6] = (mode[6] == 'x' ? 's' : 'S');
errno = 0;
pw = getpwuid(ent->uid);

2
wc.c
View File

@ -75,7 +75,7 @@ wc(FILE *fp, const char *str)
long nc = 0, nl = 0, nw = 0;
while((c = fgetc(fp)) != EOF) {
if(cmode != 'm' || (c & 0xc0) != 0x80)
if(cmode != 'm' || (c & 0xc0) != 0x80) /* utf8 */
nc++;
if(c == '\n')
nl++;