ls cleanup
This commit is contained in:
parent
2dfe5c6b8b
commit
0a3a8c55e4
31
ls.c
31
ls.c
|
@ -150,7 +150,8 @@ mkent(Entry *ent, char *path)
|
||||||
void
|
void
|
||||||
output(Entry *ent)
|
output(Entry *ent)
|
||||||
{
|
{
|
||||||
char buf[BUFSIZ], mode[11], *fmt;
|
char buf[BUFSIZ], *fmt;
|
||||||
|
char mode[] = "----------";
|
||||||
struct group *gr;
|
struct group *gr;
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
|
|
||||||
|
@ -175,24 +176,18 @@ output(Entry *ent)
|
||||||
else
|
else
|
||||||
mode[0] = '?';
|
mode[0] = '?';
|
||||||
|
|
||||||
mode[1] = (ent->mode & S_IRUSR) ? 'r' : '-';
|
if(ent->mode & S_IRUSR) mode[1] = 'r';
|
||||||
mode[2] = (ent->mode & S_IWUSR) ? 'w' : '-';
|
if(ent->mode & S_IWUSR) mode[2] = 'w';
|
||||||
if(ent->mode & S_ISUID)
|
if(ent->mode & S_IXUSR) mode[3] = 'x';
|
||||||
mode[3] = (ent->mode & S_IXUSR) ? 's' : 'S';
|
if(ent->mode & S_IRGRP) mode[4] = 'r';
|
||||||
else
|
if(ent->mode & S_IWGRP) mode[5] = 'w';
|
||||||
mode[3] = (ent->mode & S_IXUSR) ? 'x' : '-';
|
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' : '-';
|
if(ent->mode & S_ISUID) mode[3] = (mode[3] == 'x' ? 's' : 'S');
|
||||||
mode[5] = (ent->mode & S_IWGRP) ? 'w' : '-';
|
if(ent->mode & S_ISGID) mode[6] = (mode[6] == 'x' ? 's' : 'S');
|
||||||
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';
|
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
pw = getpwuid(ent->uid);
|
pw = getpwuid(ent->uid);
|
||||||
|
|
2
wc.c
2
wc.c
|
@ -75,7 +75,7 @@ wc(FILE *fp, const char *str)
|
||||||
long nc = 0, nl = 0, nw = 0;
|
long nc = 0, nl = 0, nw = 0;
|
||||||
|
|
||||||
while((c = fgetc(fp)) != EOF) {
|
while((c = fgetc(fp)) != EOF) {
|
||||||
if(cmode != 'm' || (c & 0xc0) != 0x80)
|
if(cmode != 'm' || (c & 0xc0) != 0x80) /* utf8 */
|
||||||
nc++;
|
nc++;
|
||||||
if(c == '\n')
|
if(c == '\n')
|
||||||
nl++;
|
nl++;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user