Deleted Added
full compact
1c1
< /* $NetBSD: stat.c,v 1.3 2002/05/31 16:45:16 atatat Exp $ */
---
> /* $NetBSD: stat.c,v 1.6 2002/07/09 21:25:00 atatat Exp $ */
39c39
< #include <sys/cdefs.h>
---
> #if 0
41,42c41
< __RCSID("$NetBSD: stat.c,v 1.3 2002/05/31 16:45:16 atatat Exp $");
< __FBSDID("$FreeBSD: head/usr.bin/stat/stat.c 97953 2002-06-06 19:27:17Z dougb $");
---
> __RCSID("$NetBSD: stat.c,v 1.6 2002/07/09 21:25:00 atatat Exp $");
43a43
> #endif
45,46c45,47
< #include <sys/types.h>
< #include <sys/param.h>
---
> #include <sys/cdefs.h>
> __FBSDID("$FreeBSD: head/usr.bin/stat/stat.c 101773 2002-08-13 08:23:49Z dougb $");
>
48c49,51
< #include <unistd.h>
---
> #include <sys/syslimits.h>
>
> #include <ctype.h>
50c53,54
< #include <string.h>
---
> #include <grp.h>
> #include <pwd.h>
52,53d55
< #include <ctype.h>
< #include <stddef.h>
55,56c57,59
< #include <pwd.h>
< #include <grp.h>
---
> #include <string.h>
> #include <time.h>
> #include <unistd.h>
108a112,118
> #define FMTF_DECIMAL 0x01
> #define FMTF_OCTAL 0x02
> #define FMTF_UNSIGNED 0x04
> #define FMTF_HEX 0x08
> #define FMTF_FLOAT 0x10
> #define FMTF_STRING 0x20
>
133c143
< void usage(void);
---
> void usage(const char *);
135c145
< const char *, int, int);
---
> const char *, int, int, int);
143a154
> int linkfail;
145c156
< #define addchar(b, n, l, c, nl) \
---
> #define addchar(s, c, nl) \
147,150c158,159
< if ((*(n)) < (l)) { \
< (b)[(*(n))++] = (c); \
< (*nl) = ((c) == '\n'); \
< } \
---
> (void)fputc((c), (s)); \
> (*nl) = ((c) == '\n'); \
157,159c166,168
< int ch, rc, errs;
< int lsF, fmtchar, usestat, fn, nonl;
< char *statfmt;
---
> int ch, rc, errs, am_readlink;
> int lsF, fmtchar, usestat, fn, nonl, quiet;
> char *statfmt, *options, *synopsis;
160a170
> am_readlink = 0;
164a175,176
> quiet = 0;
> linkfail = 0;
168c180,192
< while ((ch = getopt(argc, argv, "f:FlLnrst:x")) != -1)
---
> if (strcmp(getprogname(), "readlink") == 0) {
> am_readlink = 1;
> options = "n";
> synopsis = "[-n] [file ...]";
> statfmt = "%Y";
> fmtchar = 'f';
> quiet = 1;
> } else {
> options = "f:FlLnqrst:x";
> synopsis = "[-FlLnqrsx] [-f format] [-t timefmt] [file ...]";
> }
>
> while ((ch = getopt(argc, argv, options)) != -1)
178a203,205
> case 'q':
> quiet = 1;
> break;
195c222
< usage();
---
> usage(synopsis);
233c260
< usage();
---
> usage(synopsis);
251c278,281
< warn("%s: stat", argc == 0 ? "(stdin)" : argv[0]);
---
> linkfail = 1;
> if (!quiet)
> warn("%s: stat",
> argc == 0 ? "(stdin)" : argv[0]);
254c284
< output(&st, argv[0], statfmt, fn, nonl);
---
> output(&st, argv[0], statfmt, fn, nonl, quiet);
261c291
< return (errs);
---
> return (am_readlink ? linkfail : errs);
265c295
< usage(void)
---
> usage(const char *synopsis)
268,270c298
< (void)fprintf(stderr,
< "usage: %s [-FlLnrsx] [-f format] [-t timefmt] [file ...]\n",
< getprogname());
---
> (void)fprintf(stderr, "usage: %s %s\n", getprogname(), synopsis);
279c307
< const char *statfmt, int fn, int nonl)
---
> const char *statfmt, int fn, int nonl, int quiet)
282c310
< char buf[4096], subbuf[MAXPATHLEN];
---
> char buf[PATH_MAX];
285d312
< size_t len;
287c314
< len = 0;
---
> nl = 1;
294c321
< addchar(buf, &len, sizeof(buf), *statfmt, &nl);
---
> addchar(stdout, *statfmt, &nl);
311c338
< addchar(buf, &len, sizeof(buf), '\n', &nl);
---
> addchar(stdout, '\n', &nl);
315c342
< addchar(buf, &len, sizeof(buf), '\t', &nl);
---
> addchar(stdout, '\t', &nl);
319c346
< addchar(buf, &len, sizeof(buf), '%', &nl);
---
> addchar(stdout, '%', &nl);
327c354
< addchar(buf, &len, sizeof(buf), *p, &nl);
---
> addchar(stdout, *p, &nl);
396c423,424
< #define fmtcase(x, y) case (y): (x) = (y); statfmt++; break
---
> #define fmtcase(x, y) case (y): (x) = (y); statfmt++; break
> #define fmtcasef(x, y, z) case (y): (x) = (z); statfmt++; break
398,403c426,431
< fmtcase(ofmt, FMT_DECIMAL);
< fmtcase(ofmt, FMT_OCTAL);
< fmtcase(ofmt, FMT_UNSIGNED);
< fmtcase(ofmt, FMT_HEX);
< fmtcase(ofmt, FMT_FLOAT);
< fmtcase(ofmt, FMT_STRING);
---
> fmtcasef(ofmt, FMT_DECIMAL, FMTF_DECIMAL);
> fmtcasef(ofmt, FMT_OCTAL, FMTF_OCTAL);
> fmtcasef(ofmt, FMT_UNSIGNED, FMTF_UNSIGNED);
> fmtcasef(ofmt, FMT_HEX, FMTF_HEX);
> fmtcasef(ofmt, FMT_FLOAT, FMTF_FLOAT);
> fmtcasef(ofmt, FMT_STRING, FMTF_STRING);
440a469
> #undef fmtcasef
446c475
< subbuf, sizeof(subbuf),
---
> buf, sizeof(buf),
449,450c478,479
< for (i = 0; i < t && i < sizeof(subbuf); i++)
< addchar(buf, &len, sizeof(buf), subbuf[i], &nl);
---
> for (i = 0; i < t && i < sizeof(buf); i++)
> addchar(stdout, buf[i], &nl);
459d487
< (void)write(STDOUT_FILENO, buf, len);
461c489,490
< (void)write(STDOUT_FILENO, "\n", sizeof("\n") - 1);
---
> (void)fputc('\n', stdout);
> (void)fflush(stdout);
477c506
< char smode[12], sid[12], path[MAXPATHLEN + 4];
---
> char smode[12], sid[12], path[PATH_MAX + 4];
514,515c543,544
< formats = FMT_DECIMAL | FMT_OCTAL | FMT_UNSIGNED | FMT_HEX |
< FMT_STRING;
---
> formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX |
> FMTF_STRING;
517c546
< ofmt = FMT_UNSIGNED;
---
> ofmt = FMTF_UNSIGNED;
523c552
< formats = FMT_DECIMAL | FMT_OCTAL | FMT_UNSIGNED | FMT_HEX;
---
> formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX;
525c554
< ofmt = FMT_UNSIGNED;
---
> ofmt = FMTF_UNSIGNED;
553,554c582,583
< formats = FMT_DECIMAL | FMT_OCTAL | FMT_UNSIGNED | FMT_HEX |
< FMT_STRING;
---
> formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX |
> FMTF_STRING;
556c585
< ofmt = FMT_OCTAL;
---
> ofmt = FMTF_OCTAL;
562c591
< formats = FMT_DECIMAL | FMT_OCTAL | FMT_UNSIGNED | FMT_HEX;
---
> formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX;
564c593
< ofmt = FMT_UNSIGNED;
---
> ofmt = FMTF_UNSIGNED;
575,576c604,605
< formats = FMT_DECIMAL | FMT_OCTAL | FMT_UNSIGNED | FMT_HEX |
< FMT_STRING;
---
> formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX |
> FMTF_STRING;
578c607
< ofmt = FMT_UNSIGNED;
---
> ofmt = FMTF_UNSIGNED;
589,590c618,619
< formats = FMT_DECIMAL | FMT_OCTAL | FMT_UNSIGNED | FMT_HEX |
< FMT_STRING;
---
> formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX |
> FMTF_STRING;
592c621
< ofmt = FMT_UNSIGNED;
---
> ofmt = FMTF_UNSIGNED;
611,612c640,641
< formats = FMT_DECIMAL | FMT_OCTAL | FMT_UNSIGNED | FMT_HEX |
< FMT_FLOAT | FMT_STRING;
---
> formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX |
> FMTF_FLOAT | FMTF_STRING;
614c643
< ofmt = FMT_DECIMAL;
---
> ofmt = FMTF_DECIMAL;
620c649
< formats = FMT_DECIMAL | FMT_OCTAL | FMT_UNSIGNED | FMT_HEX;
---
> formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX;
622c651
< ofmt = FMT_UNSIGNED;
---
> ofmt = FMTF_UNSIGNED;
628c657
< formats = FMT_DECIMAL | FMT_OCTAL | FMT_UNSIGNED | FMT_HEX;
---
> formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX;
630c659
< ofmt = FMT_UNSIGNED;
---
> ofmt = FMTF_UNSIGNED;
636c665
< formats = FMT_DECIMAL | FMT_OCTAL | FMT_UNSIGNED | FMT_HEX;
---
> formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX;
638c667
< ofmt = FMT_UNSIGNED;
---
> ofmt = FMTF_UNSIGNED;
644c673
< formats = FMT_DECIMAL | FMT_OCTAL | FMT_UNSIGNED | FMT_HEX;
---
> formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX;
646c675
< ofmt = FMT_UNSIGNED;
---
> ofmt = FMTF_UNSIGNED;
652c681
< formats = FMT_DECIMAL | FMT_OCTAL | FMT_UNSIGNED | FMT_HEX;
---
> formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX;
654c683
< ofmt = FMT_UNSIGNED;
---
> ofmt = FMTF_UNSIGNED;
662a692
> linkfail = 1;
667c697
< sdata = path + (ofmt == FMT_STRING ? 0 : 4);
---
> sdata = path + (ofmt == FMTF_STRING ? 0 : 4);
669c699,700
< else
---
> else {
> linkfail = 1;
671c702,703
< formats = FMT_STRING;
---
> }
> formats = FMTF_STRING;
673c705
< ofmt = FMT_STRING;
---
> ofmt = FMTF_STRING;
709c741
< formats = FMT_STRING;
---
> formats = FMTF_STRING;
711c743
< ofmt = FMT_STRING;
---
> ofmt = FMTF_STRING;
721c753
< formats = FMT_STRING;
---
> formats = FMTF_STRING;
723c755
< ofmt = FMT_STRING;
---
> ofmt = FMTF_STRING;
785c817
< if (ofmt == FMT_FLOAT) {
---
> if (ofmt == FMTF_FLOAT) {
865c897
< if (ofmt == FMT_STRING) {
---
> if (ofmt == FMTF_STRING) {
876c908
< if (small && ofmt != FMT_DECIMAL)
---
> if (small && ofmt != FMTF_DECIMAL)
884,887c916,919
< case FMT_DECIMAL: (void)strcat(lfmt, "d"); break;
< case FMT_OCTAL: (void)strcat(lfmt, "o"); break;
< case FMT_UNSIGNED: (void)strcat(lfmt, "u"); break;
< case FMT_HEX: (void)strcat(lfmt, "x"); break;
---
> case FMTF_DECIMAL: (void)strcat(lfmt, "d"); break;
> case FMTF_OCTAL: (void)strcat(lfmt, "o"); break;
> case FMTF_UNSIGNED: (void)strcat(lfmt, "u"); break;
> case FMTF_HEX: (void)strcat(lfmt, "x"); break;