2011-05-25 23:01:20 -04:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
2015-02-14 15:02:41 -05:00
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2011-05-25 23:01:20 -04:00
|
|
|
#include <dirent.h>
|
|
|
|
#include <grp.h>
|
|
|
|
#include <pwd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
2014-11-13 12:29:30 -05:00
|
|
|
|
2015-02-17 12:59:01 -05:00
|
|
|
#include "utf.h"
|
2011-05-25 23:01:20 -04:00
|
|
|
#include "util.h"
|
|
|
|
|
2015-02-16 13:20:06 -05:00
|
|
|
struct entry {
|
|
|
|
char *name;
|
|
|
|
mode_t mode, tmode;
|
2011-05-25 23:01:20 -04:00
|
|
|
nlink_t nlink;
|
2015-02-16 13:20:06 -05:00
|
|
|
uid_t uid;
|
|
|
|
gid_t gid;
|
|
|
|
off_t size;
|
|
|
|
time_t t;
|
|
|
|
ino_t ino;
|
|
|
|
};
|
2011-05-25 23:01:20 -04:00
|
|
|
|
2015-02-21 04:30:08 -05:00
|
|
|
static int Aflag = 0;
|
2014-11-13 15:24:47 -05:00
|
|
|
static int aflag = 0;
|
2015-01-20 11:50:37 -05:00
|
|
|
static int cflag = 0;
|
2014-11-13 15:24:47 -05:00
|
|
|
static int dflag = 0;
|
|
|
|
static int Fflag = 0;
|
2015-03-18 14:26:42 -04:00
|
|
|
static int fflag = 0;
|
2014-12-07 20:33:52 -05:00
|
|
|
static int Hflag = 0;
|
2014-11-13 15:24:47 -05:00
|
|
|
static int hflag = 0;
|
|
|
|
static int iflag = 0;
|
2014-12-07 20:33:52 -05:00
|
|
|
static int Lflag = 0;
|
2014-11-13 15:24:47 -05:00
|
|
|
static int lflag = 0;
|
2015-02-22 06:55:38 -05:00
|
|
|
static int nflag = 0;
|
2015-02-19 13:48:15 -05:00
|
|
|
static int pflag = 0;
|
2015-02-17 12:59:01 -05:00
|
|
|
static int qflag = 0;
|
2015-02-21 05:45:15 -05:00
|
|
|
static int Rflag = 0;
|
2015-03-18 14:26:42 -04:00
|
|
|
static int Sflag = 0;
|
2014-11-13 15:24:47 -05:00
|
|
|
static int rflag = 0;
|
|
|
|
static int tflag = 0;
|
|
|
|
static int Uflag = 0;
|
2015-02-18 11:29:46 -05:00
|
|
|
static int uflag = 0;
|
2014-11-13 15:24:47 -05:00
|
|
|
static int first = 1;
|
|
|
|
static int many;
|
2011-05-25 23:01:20 -04:00
|
|
|
|
2015-02-21 05:45:15 -05:00
|
|
|
static void ls(const struct entry *ent, int recurse);
|
|
|
|
|
2013-06-14 14:20:47 -04:00
|
|
|
static void
|
2015-02-16 13:20:06 -05:00
|
|
|
mkent(struct entry *ent, char *path, int dostat, int follow)
|
2011-05-25 23:01:20 -04:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
2015-02-16 13:20:06 -05:00
|
|
|
ent->name = path;
|
2014-11-13 12:29:30 -05:00
|
|
|
if (!dostat)
|
2013-07-18 15:14:53 -04:00
|
|
|
return;
|
2014-12-07 20:33:52 -05:00
|
|
|
if ((follow ? stat : lstat)(path, &st) < 0)
|
|
|
|
eprintf("%s %s:", follow ? "stat" : "lstat", path);
|
2015-02-16 13:20:06 -05:00
|
|
|
ent->mode = st.st_mode;
|
|
|
|
ent->nlink = st.st_nlink;
|
|
|
|
ent->uid = st.st_uid;
|
|
|
|
ent->gid = st.st_gid;
|
|
|
|
ent->size = st.st_size;
|
2015-02-18 11:29:46 -05:00
|
|
|
if (cflag)
|
|
|
|
ent->t = st.st_ctime;
|
|
|
|
else if (uflag)
|
|
|
|
ent->t = st.st_atime;
|
|
|
|
else
|
|
|
|
ent->t = st.st_mtime;
|
2015-02-16 13:20:06 -05:00
|
|
|
ent->ino = st.st_ino;
|
2014-12-07 20:33:52 -05:00
|
|
|
if (S_ISLNK(ent->mode))
|
|
|
|
ent->tmode = stat(path, &st) == 0 ? st.st_mode : 0;
|
2011-05-25 23:01:20 -04:00
|
|
|
}
|
|
|
|
|
2014-06-01 08:59:47 -04:00
|
|
|
static char *
|
2014-02-17 09:41:09 -05:00
|
|
|
indicator(mode_t mode)
|
|
|
|
{
|
2015-02-19 13:48:15 -05:00
|
|
|
if (pflag || Fflag)
|
|
|
|
if (S_ISDIR(mode))
|
|
|
|
return "/";
|
2014-02-17 09:41:09 -05:00
|
|
|
|
2015-02-19 13:48:15 -05:00
|
|
|
if (Fflag) {
|
|
|
|
if (S_ISLNK(mode))
|
|
|
|
return "@";
|
|
|
|
else if (S_ISFIFO(mode))
|
|
|
|
return "|";
|
|
|
|
else if (S_ISSOCK(mode))
|
|
|
|
return "=";
|
|
|
|
else if (mode & S_IXUSR || mode & S_IXGRP || mode & S_IXOTH)
|
|
|
|
return "*";
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
2014-02-17 09:41:09 -05:00
|
|
|
}
|
|
|
|
|
2014-06-01 08:59:47 -04:00
|
|
|
static void
|
2015-02-16 13:20:06 -05:00
|
|
|
output(const struct entry *ent)
|
2011-05-25 23:01:20 -04:00
|
|
|
{
|
|
|
|
struct group *gr;
|
|
|
|
struct passwd *pw;
|
2015-02-16 13:20:06 -05:00
|
|
|
ssize_t len;
|
|
|
|
char buf[BUFSIZ], *fmt,
|
|
|
|
pwname[_SC_LOGIN_NAME_MAX], grname[_SC_LOGIN_NAME_MAX],
|
|
|
|
mode[] = "----------";
|
2011-05-25 23:01:20 -04:00
|
|
|
|
2013-09-27 10:32:50 -04:00
|
|
|
if (iflag)
|
|
|
|
printf("%lu ", (unsigned long)ent->ino);
|
2014-11-13 12:29:30 -05:00
|
|
|
if (!lflag) {
|
2014-02-17 09:41:09 -05:00
|
|
|
printf("%s%s\n", ent->name, indicator(ent->mode));
|
2011-05-25 23:01:20 -04:00
|
|
|
return;
|
|
|
|
}
|
2014-11-13 12:29:30 -05:00
|
|
|
if (S_ISREG(ent->mode))
|
2011-05-25 23:01:20 -04:00
|
|
|
mode[0] = '-';
|
2014-11-13 12:29:30 -05:00
|
|
|
else if (S_ISBLK(ent->mode))
|
2011-05-25 23:01:20 -04:00
|
|
|
mode[0] = 'b';
|
2014-11-13 12:29:30 -05:00
|
|
|
else if (S_ISCHR(ent->mode))
|
2011-05-25 23:01:20 -04:00
|
|
|
mode[0] = 'c';
|
2014-11-13 12:29:30 -05:00
|
|
|
else if (S_ISDIR(ent->mode))
|
2011-05-25 23:01:20 -04:00
|
|
|
mode[0] = 'd';
|
2014-11-13 12:29:30 -05:00
|
|
|
else if (S_ISFIFO(ent->mode))
|
2011-05-25 23:01:20 -04:00
|
|
|
mode[0] = 'p';
|
2014-11-13 12:29:30 -05:00
|
|
|
else if (S_ISLNK(ent->mode))
|
2011-05-25 23:01:20 -04:00
|
|
|
mode[0] = 'l';
|
2014-11-13 12:29:30 -05:00
|
|
|
else if (S_ISSOCK(ent->mode))
|
2011-05-25 23:01:20 -04:00
|
|
|
mode[0] = 's';
|
|
|
|
else
|
|
|
|
mode[0] = '?';
|
|
|
|
|
2014-11-13 12:29:30 -05:00
|
|
|
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';
|
2011-05-27 18:56:43 -04:00
|
|
|
|
2014-11-13 12:29:30 -05:00
|
|
|
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';
|
2011-05-25 23:01:20 -04:00
|
|
|
|
2015-02-22 06:55:38 -05:00
|
|
|
if (!nflag && (pw = getpwuid(ent->uid)))
|
2015-02-16 13:20:06 -05:00
|
|
|
snprintf(pwname, LEN(pwname), "%s", pw->pw_name);
|
2014-12-21 16:58:09 -05:00
|
|
|
else
|
2015-02-16 13:20:06 -05:00
|
|
|
snprintf(pwname, LEN(pwname), "%d", ent->uid);
|
2011-05-25 23:01:20 -04:00
|
|
|
|
2015-02-22 06:55:38 -05:00
|
|
|
if (!nflag && (gr = getgrgid(ent->gid)))
|
2015-02-16 13:20:06 -05:00
|
|
|
snprintf(grname, LEN(grname), "%s", gr->gr_name);
|
2014-12-21 16:58:09 -05:00
|
|
|
else
|
2015-02-16 13:20:06 -05:00
|
|
|
snprintf(grname, LEN(grname), "%d", ent->gid);
|
2011-05-25 23:01:20 -04:00
|
|
|
|
2015-02-16 13:20:06 -05:00
|
|
|
if (time(NULL) > ent->t + (180 * 24 * 60 * 60)) /* 6 months ago? */
|
2011-06-04 07:40:05 -04:00
|
|
|
fmt = "%b %d %Y";
|
2011-05-25 23:01:20 -04:00
|
|
|
else
|
|
|
|
fmt = "%b %d %H:%M";
|
|
|
|
|
2015-02-16 13:20:06 -05:00
|
|
|
strftime(buf, sizeof(buf), fmt, localtime(&ent->t));
|
2014-10-19 05:48:04 -04:00
|
|
|
printf("%s %4ld %-8.8s %-8.8s ", mode, (long)ent->nlink, pwname, grname);
|
2015-02-22 06:55:38 -05:00
|
|
|
|
2014-11-13 12:29:30 -05:00
|
|
|
if (hflag)
|
2015-04-24 18:27:20 -04:00
|
|
|
printf("%10s ", humansize(ent->size));
|
2014-10-19 05:48:04 -04:00
|
|
|
else
|
|
|
|
printf("%10lu ", (unsigned long)ent->size);
|
|
|
|
printf("%s %s%s", buf, ent->name, indicator(ent->mode));
|
2014-11-13 12:29:30 -05:00
|
|
|
if (S_ISLNK(ent->mode)) {
|
2015-02-16 13:20:06 -05:00
|
|
|
if ((len = readlink(ent->name, buf, sizeof(buf) - 1)) < 0)
|
2011-06-04 07:40:05 -04:00
|
|
|
eprintf("readlink %s:", ent->name);
|
|
|
|
buf[len] = '\0';
|
2014-12-07 20:33:52 -05:00
|
|
|
printf(" -> %s%s", buf, indicator(ent->tmode));
|
2011-06-04 07:40:05 -04:00
|
|
|
}
|
|
|
|
putchar('\n');
|
2011-05-25 23:01:20 -04:00
|
|
|
}
|
2015-02-16 13:20:06 -05:00
|
|
|
|
|
|
|
static int
|
|
|
|
entcmp(const void *va, const void *vb)
|
|
|
|
{
|
2015-03-18 14:26:42 -04:00
|
|
|
int cmp = 0;
|
2015-02-16 13:20:06 -05:00
|
|
|
const struct entry *a = va, *b = vb;
|
|
|
|
|
2015-03-18 14:26:42 -04:00
|
|
|
if (Sflag)
|
|
|
|
cmp = b->size - a->size;
|
|
|
|
else if (tflag)
|
|
|
|
cmp = b->t - a->t;
|
|
|
|
|
|
|
|
return cmp ? cmp : strcmp(a->name, b->name);
|
2015-02-16 13:20:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
lsdir(const char *path)
|
|
|
|
{
|
|
|
|
DIR *dp;
|
2015-02-17 12:59:01 -05:00
|
|
|
Rune r;
|
2015-02-16 13:20:06 -05:00
|
|
|
struct entry ent, *ents = NULL;
|
|
|
|
struct dirent *d;
|
2015-02-18 10:55:57 -05:00
|
|
|
size_t i, n = 0, len;
|
2015-03-18 10:20:35 -04:00
|
|
|
char cwd[PATH_MAX], *p, *q, *name;
|
2015-02-16 13:20:06 -05:00
|
|
|
|
2015-03-18 10:20:35 -04:00
|
|
|
if (!getcwd(cwd, sizeof(cwd)))
|
|
|
|
eprintf("getcwd:");
|
2015-02-16 13:20:06 -05:00
|
|
|
if (!(dp = opendir(path)))
|
|
|
|
eprintf("opendir %s:", path);
|
|
|
|
if (chdir(path) < 0)
|
|
|
|
eprintf("chdir %s:", path);
|
|
|
|
|
2015-02-21 05:45:15 -05:00
|
|
|
if (many || Rflag) {
|
2015-02-16 13:20:06 -05:00
|
|
|
if (!first)
|
|
|
|
putchar('\n');
|
|
|
|
printf("%s:\n", path);
|
|
|
|
}
|
2015-02-21 05:45:15 -05:00
|
|
|
first = 0;
|
2015-02-16 13:20:06 -05:00
|
|
|
|
|
|
|
while ((d = readdir(dp))) {
|
2015-02-21 04:30:08 -05:00
|
|
|
if (d->d_name[0] == '.' && !aflag && !Aflag)
|
2015-02-16 13:20:06 -05:00
|
|
|
continue;
|
2015-02-21 04:30:08 -05:00
|
|
|
else if (Aflag)
|
|
|
|
if (strcmp(d->d_name, ".") == 0 || strcmp(d->d_name, "..") == 0)
|
|
|
|
continue;
|
2015-02-16 13:20:06 -05:00
|
|
|
if (Uflag){
|
2015-02-21 05:45:15 -05:00
|
|
|
mkent(&ent, d->d_name, Fflag || lflag || pflag || iflag || Rflag, Lflag);
|
|
|
|
ls(&ent, Rflag);
|
2015-02-16 13:20:06 -05:00
|
|
|
} else {
|
2015-03-10 16:16:21 -04:00
|
|
|
ents = ereallocarray(ents, ++n, sizeof(*ents));
|
2015-02-18 11:48:07 -05:00
|
|
|
name = p = estrdup(d->d_name);
|
2015-02-17 12:59:01 -05:00
|
|
|
if (qflag) {
|
2015-02-18 10:55:57 -05:00
|
|
|
q = d->d_name;
|
2015-02-18 11:43:18 -05:00
|
|
|
while (*q) {
|
|
|
|
len = chartorune(&r, q);
|
2015-02-17 12:59:01 -05:00
|
|
|
if (isprintrune(r)) {
|
2015-02-18 10:55:57 -05:00
|
|
|
memcpy(p, q, len);
|
|
|
|
p += len, q += len;
|
|
|
|
} else {
|
|
|
|
*p++ = '?';
|
|
|
|
q += len;
|
2015-02-17 12:59:01 -05:00
|
|
|
}
|
|
|
|
}
|
2015-02-18 11:43:18 -05:00
|
|
|
*p = '\0';
|
2015-02-17 12:59:01 -05:00
|
|
|
}
|
2015-02-21 05:45:15 -05:00
|
|
|
mkent(&ents[n - 1], name, tflag || Fflag || iflag || lflag || pflag || Rflag, Lflag);
|
2015-02-16 13:20:06 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir(dp);
|
|
|
|
if (!Uflag){
|
|
|
|
qsort(ents, n, sizeof(*ents), entcmp);
|
|
|
|
for (i = 0; i < n; i++) {
|
2015-02-21 05:45:15 -05:00
|
|
|
ls(&ents[rflag ? (n - i - 1) : i], Rflag);
|
2015-02-16 13:20:06 -05:00
|
|
|
free(ents[rflag ? (n - i - 1) : i].name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (chdir(cwd) < 0)
|
|
|
|
eprintf("chdir %s:", cwd);
|
|
|
|
free(ents);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-02-21 05:45:15 -05:00
|
|
|
ls(const struct entry *ent, int recurse)
|
2015-02-16 13:20:06 -05:00
|
|
|
{
|
2015-02-21 05:45:15 -05:00
|
|
|
if (recurse && (S_ISDIR(ent->mode) || (S_ISLNK(ent->mode) &&
|
2015-02-16 13:20:06 -05:00
|
|
|
S_ISDIR(ent->tmode) && !Fflag && !lflag)) && !dflag)
|
|
|
|
lsdir(ent->name);
|
|
|
|
else
|
|
|
|
output(ent);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
2015-02-21 05:45:15 -05:00
|
|
|
eprintf("usage: %s [-1AacdFHhiLlqRrtUu] [file ...]\n", argv0);
|
2015-02-16 13:20:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
2015-03-10 17:19:19 -04:00
|
|
|
struct entry *ents;
|
2015-02-16 13:20:06 -05:00
|
|
|
size_t i;
|
|
|
|
|
|
|
|
ARGBEGIN {
|
|
|
|
case '1':
|
|
|
|
/* ignore */
|
|
|
|
break;
|
2015-02-21 04:30:08 -05:00
|
|
|
case 'A':
|
|
|
|
Aflag = 1;
|
|
|
|
break;
|
2015-02-16 13:20:06 -05:00
|
|
|
case 'a':
|
|
|
|
aflag = 1;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
cflag = 1;
|
2015-02-18 11:29:46 -05:00
|
|
|
uflag = 0;
|
2015-02-16 13:20:06 -05:00
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
dflag = 1;
|
|
|
|
break;
|
2015-03-18 14:26:42 -04:00
|
|
|
case 'f':
|
|
|
|
aflag = 1;
|
|
|
|
fflag = 1;
|
|
|
|
Uflag = 1;
|
|
|
|
break;
|
2015-02-16 13:20:06 -05:00
|
|
|
case 'F':
|
|
|
|
Fflag = 1;
|
|
|
|
break;
|
|
|
|
case 'H':
|
|
|
|
Hflag = 1;
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
hflag = 1;
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
iflag = 1;
|
|
|
|
break;
|
|
|
|
case 'L':
|
|
|
|
Lflag = 1;
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
lflag = 1;
|
|
|
|
break;
|
2015-02-22 06:55:38 -05:00
|
|
|
case 'n':
|
|
|
|
lflag = 1;
|
|
|
|
nflag = 1;
|
|
|
|
break;
|
2015-02-19 13:48:15 -05:00
|
|
|
case 'p':
|
|
|
|
pflag = 1;
|
|
|
|
break;
|
2015-02-17 12:59:01 -05:00
|
|
|
case 'q':
|
|
|
|
qflag = 1;
|
|
|
|
break;
|
2015-02-21 05:45:15 -05:00
|
|
|
case 'R':
|
|
|
|
Rflag = 1;
|
|
|
|
break;
|
2015-02-16 13:20:06 -05:00
|
|
|
case 'r':
|
2015-03-18 14:26:42 -04:00
|
|
|
if (!fflag)
|
|
|
|
rflag = 1;
|
|
|
|
break;
|
|
|
|
case 'S':
|
|
|
|
Sflag = 1;
|
|
|
|
tflag = 0;
|
2015-02-16 13:20:06 -05:00
|
|
|
break;
|
|
|
|
case 't':
|
2015-03-18 14:26:42 -04:00
|
|
|
Sflag = 0;
|
2015-02-16 13:20:06 -05:00
|
|
|
tflag = 1;
|
|
|
|
break;
|
|
|
|
case 'U':
|
|
|
|
Uflag = 1;
|
|
|
|
break;
|
2015-02-18 11:29:46 -05:00
|
|
|
case 'u':
|
|
|
|
uflag = 1;
|
|
|
|
cflag = 0;
|
|
|
|
break;
|
2015-02-16 13:20:06 -05:00
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
} ARGEND;
|
|
|
|
|
|
|
|
many = (argc > 1);
|
|
|
|
if (argc == 0)
|
|
|
|
*--argv = ".", argc++;
|
|
|
|
|
2015-03-11 05:50:18 -04:00
|
|
|
ents = ereallocarray(NULL, argc, sizeof(*ents));
|
2015-02-16 13:20:06 -05:00
|
|
|
|
|
|
|
for (i = 0; i < argc; i++)
|
|
|
|
mkent(&ents[i], argv[i], 1, Hflag || Lflag);
|
|
|
|
qsort(ents, argc, sizeof(*ents), entcmp);
|
|
|
|
for (i = 0; i < argc; i++)
|
2015-02-21 05:45:15 -05:00
|
|
|
ls(&ents[rflag ? argc-i-1 : i], 1);
|
2015-02-16 13:20:06 -05:00
|
|
|
|
Add *fshut() functions to properly flush file streams
This has been a known issue for a long time. Example:
printf "word" > /dev/full
wouldn't report there's not enough space on the device.
This is due to the fact that every libc has internal buffers
for stdout which store fragments of written data until they reach
a certain size or on some callback to flush them all at once to the
kernel.
You can force the libc to flush them with fflush(). In case flushing
fails, you can check the return value of fflush() and report an error.
However, previously, sbase didn't have such checks and without fflush(),
the libc silently flushes the buffers on exit without checking the errors.
No offense, but there's no way for the libc to report errors in the exit-
condition.
GNU coreutils solve this by having onexit-callbacks to handle the flushing
and report issues, but they have obvious deficiencies.
After long discussions on IRC, we came to the conclusion that checking the
return value of every io-function would be a bit too much, and having a
general-purpose fclose-wrapper would be the best way to go.
It turned out that fclose() alone is not enough to detect errors. The right
way to do it is to fflush() + check ferror on the fp and then to a fclose().
This is what fshut does and that's how it's done before each return.
The return value is obviously affected, reporting an error in case a flush
or close failed, but also when reading failed for some reason, the error-
state is caught.
the !!( ... + ...) construction is used to call all functions inside the
brackets and not "terminating" on the first.
We want errors to be reported, but there's no reason to stop flushing buffers
when one other file buffer has issues.
Obviously, functionales come before the flush and ret-logic comes after to
prevent early exits as well without reporting warnings if there are any.
One more advantage of fshut() is that it is even able to report errors
on obscure NFS-setups which the other coreutils are unable to detect,
because they only check the return-value of fflush() and fclose(),
not ferror() as well.
2015-04-04 15:25:17 -04:00
|
|
|
return fshut(stdout, "<stdout>");
|
2015-02-16 13:20:06 -05:00
|
|
|
}
|