static void printpath(off_t n, const char *path) { if (hflag) printf("%s\t%s\n", humansize(n * blksize), path); else printf("%ju\t%s\n", n, path); }
static void display_params(int logN, uint32_t r, uint32_t p, size_t memlimit, double opps, double maxtime) { uint64_t N = (uint64_t)(1) << logN; uint64_t mem_minimum = 128 * r * N; double expected_seconds = 4 * N * p / opps; char * human_memlimit = humansize(memlimit); char * human_mem_minimum = humansize(mem_minimum); fprintf(stderr, "Parameters used: N = %" PRIu64 "; r = %" PRIu32 "; p = %" PRIu32 ";\n", N, r, p); fprintf(stderr, " This requires at least %s bytes of memory " "(%s available),\n", human_mem_minimum, human_memlimit); fprintf(stderr, " and will take approximately %.1f seconds " "(limit: %.1f seconds).\n", expected_seconds, maxtime); free(human_memlimit); free(human_mem_minimum); }
static void output(const struct entry *ent) { struct group *gr; struct passwd *pw; ssize_t len; char buf[BUFSIZ], *fmt, pwname[_SC_LOGIN_NAME_MAX], grname[_SC_LOGIN_NAME_MAX], mode[] = "----------"; if (iflag) printf("%lu ", (unsigned long)ent->ino); if (!lflag) { printf("%s%s\n", ent->name, indicator(ent->mode)); return; } if (S_ISREG(ent->mode)) mode[0] = '-'; else if (S_ISBLK(ent->mode)) mode[0] = 'b'; else if (S_ISCHR(ent->mode)) mode[0] = 'c'; else if (S_ISDIR(ent->mode)) mode[0] = 'd'; else if (S_ISFIFO(ent->mode)) mode[0] = 'p'; else if (S_ISLNK(ent->mode)) mode[0] = 'l'; else if (S_ISSOCK(ent->mode)) mode[0] = 's'; else mode[0] = '?'; 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'; if (ent->mode & S_ISUID) mode[3] = (mode[3] == 'x') ? 's' : 'S'; if (ent->mode & S_ISGID) mode[6] = (mode[6] == 'x') ? 's' : 'S'; if (ent->mode & S_ISVTX) mode[9] = (mode[9] == 'x') ? 't' : 'T'; if (!nflag && (pw = getpwuid(ent->uid))) snprintf(pwname, LEN(pwname), "%s", pw->pw_name); else snprintf(pwname, LEN(pwname), "%d", ent->uid); if (!nflag && (gr = getgrgid(ent->gid))) snprintf(grname, LEN(grname), "%s", gr->gr_name); else snprintf(grname, LEN(grname), "%d", ent->gid); if (time(NULL) > ent->t + (180 * 24 * 60 * 60)) /* 6 months ago? */ fmt = "%b %d %Y"; else fmt = "%b %d %H:%M"; strftime(buf, sizeof(buf), fmt, localtime(&ent->t)); printf("%s %4ld %-8.8s %-8.8s ", mode, (long)ent->nlink, pwname, grname); if (hflag) printf("%10s ", humansize(ent->size)); else printf("%10lu ", (unsigned long)ent->size); printf("%s %s%s", buf, ent->name, indicator(ent->mode)); if (S_ISLNK(ent->mode)) { if ((len = readlink(ent->name, buf, sizeof(buf) - 1)) < 0) eprintf("readlink %s:", ent->name); buf[len] = '\0'; printf(" -> %s%s", buf, indicator(ent->tmode)); } putchar('\n'); }