diff options
-rw-r--r-- | ls.c | 37 |
1 files changed, 21 insertions, 16 deletions
@@ -60,9 +60,11 @@ xgetpwuid(uid_t uid) (int)uid, next, cache[next] ? cache[next] : "?"); next++; - if (CACHE_SIZE == next) next = 0; - if (used < CACHE_SIZE) used++; - + if (CACHE_SIZE == next) + next = 0; + if (used < CACHE_SIZE) + used++; + return pw ? pw->pw_name : NULL; } @@ -98,9 +100,11 @@ xgetgrgid(gid_t gid) (int)gid,next,cache[next] ? cache[next] : "?"); next++; - if (CACHE_SIZE == next) next = 0; - if (used < CACHE_SIZE) used++; - + if (CACHE_SIZE == next) + next = 0; + if (used < CACHE_SIZE) + used++; + return gr ? gr->gr_name : NULL; } @@ -176,7 +180,7 @@ static void strmode(mode_t mode, char *dest) case S_IFSOCK: dest[0] = '='; break; default: dest[0] = '?'; break; } - + /* access rights */ sprintf(dest+1,"%s%s%s", rwx[(mode >> 6) & 0x7], @@ -185,7 +189,7 @@ static void strmode(mode_t mode, char *dest) } #endif -static char* +static char* ls(time_t now, char *hostname, char *filename, char *path, int *length) { DIR *dir; @@ -236,15 +240,16 @@ ls(time_t now, char *hostname, char *filename, char *path, int *length) count--; continue; } - + files[count]->r = 0; if (S_ISDIR(files[count]->s.st_mode) || S_ISREG(files[count]->s.st_mode)) { - if (access(line, R_OK) == 0) files[count]->r = 1; + if (access(line, R_OK) == 0) + files[count]->r = 1; } } closedir(dir); - + /* sort */ if (count) qsort(files,count,sizeof(struct myfile*),compare_files); @@ -306,21 +311,21 @@ ls(time_t now, char *hostname, char *filename, char *path, int *length) len += 10; buf[len++] = ' '; buf[len++] = ' '; - + /* user */ pw = xgetpwuid(files[i]->s.st_uid); if (NULL != pw) len += snprintf(buf+len, size-len, "%-8.8s ",pw); else len += snprintf(buf+len, size-len, "%8d ",(int)files[i]->s.st_uid); - + /* group */ gr = xgetgrgid(files[i]->s.st_gid); if (NULL != gr) len += snprintf(buf+len, size-len, "%-8.8s ",gr); else len += snprintf(buf+len, size-len, "%8d ",(int)files[i]->s.st_gid); - + /* mtime */ if (now - files[i]->s.st_mtime > 60*60*24*30*6) len += strftime(buf+len, size-len, "%b %d %Y ", @@ -328,7 +333,7 @@ ls(time_t now, char *hostname, char *filename, char *path, int *length) else len += strftime(buf+len, size-len, "%b %d %H:%M ", gmtime(&files[i]->s.st_mtime)); - + /* size */ if (S_ISDIR(files[i]->s.st_mode)) { len += snprintf(buf+len, size-len, " <DIR> "); @@ -350,7 +355,7 @@ ls(time_t now, char *hostname, char *filename, char *path, int *length) len += snprintf(buf+len, size-len, "%4d TB ", (int)(files[i]->s.st_size>>40)); } - + /* filename */ if (files[i]->r) { len += snprintf(buf+len, size-len, "<a href=\"%s%s\">%s</a>\n", |