+ permstring(permbuf, buf.st_mode);
+
+ if (buf.st_mtime) {
+ mt = gmtime(&buf.st_mtime);
+
+ snprintf(datebuf, sizeof datebuf,
+ "%04d-%02d-%02d %02d:%02d:%02d",
+ (int)mt->tm_year + 1900,
+ (int)mt->tm_mon + 1,
+ (int)mt->tm_mday,
+ (int)mt->tm_hour,
+ (int)mt->tm_min,
+ (int)mt->tm_sec);
+ } else
+ strlcpy(datebuf, " ", sizeof datebuf);
+
+ /* TODO: Perhaps escape special characters in fname? */
+
+ printf("%s ", permbuf);
+ if (S_ISCHR(buf.st_mode) || S_ISBLK(buf.st_mode)) {
+ printf("%5ld,%6ld",
+ (long)major(buf.st_rdev),
+ (long)minor(buf.st_rdev));
+ } else /* NB: use double for size since it might not fit in a long. */
+ printf("%12.0f", (double)buf.st_size);
+ printf(" %6ld.%-6ld %6ld %s %s%s\n",
+ (long)buf.st_uid, (long)buf.st_gid, (long)buf.st_nlink,
+ datebuf, fname, linkbuf);
+}
+
+static struct poptOption long_options[] = {
+ /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
+#ifdef SUPPORT_XATTRS
+ {"fake-super", 'f', POPT_ARG_VAL, &am_root, -1, 0, 0 },
+#endif
+ {"help", 'h', POPT_ARG_NONE, 0, 'h', 0, 0 },
+ {0,0,0,0,0,0,0}
+};
+
+static void tls_usage(int ret)
+{
+ FILE *F = ret ? stderr : stdout;
+ fprintf(F,"usage: " PROGRAM " [OPTIONS] FILE ...\n");
+ fprintf(F,"Trivial file listing program for portably checking rsync\n");
+ fprintf(F,"\nOptions:\n");
+#ifdef SUPPORT_XATTRS
+ fprintf(F," -f, --fake-super display attributes including fake-super xattrs\n");
+#endif
+ fprintf(F," -h, --help show this help\n");
+ exit(ret);
+}
+
+int
+main(int argc, char *argv[])
+{
+ poptContext pc;
+ const char **extra_args;
+ int opt;
+
+ pc = poptGetContext(PROGRAM, argc, (const char **)argv,
+ long_options, 0);
+ while ((opt = poptGetNextOpt(pc)) != -1) {
+ switch (opt) {
+ case 'h':
+ tls_usage(0);
+ default:
+ fprintf(stderr,
+ "%s: %s\n",
+ poptBadOption(pc, POPT_BADOPTION_NOALIAS),
+ poptStrerror(opt));
+ tls_usage(1);
+ }