+mode_t
+mode_from_chars (const char *p, size_t s)
+{
+ /* Do not complain about unrecognized mode bits. */
+ unsigned u = from_chars (p, s, "mode_t",
+ - (uintmax_t) TYPE_MINIMUM (mode_t),
+ TYPE_MAXIMUM (uintmax_t));
+ return ((u & TSUID ? S_ISUID : 0)
+ | (u & TSGID ? S_ISGID : 0)
+ | (u & TSVTX ? S_ISVTX : 0)
+ | (u & TUREAD ? S_IRUSR : 0)
+ | (u & TUWRITE ? S_IWUSR : 0)
+ | (u & TUEXEC ? S_IXUSR : 0)
+ | (u & TGREAD ? S_IRGRP : 0)
+ | (u & TGWRITE ? S_IWGRP : 0)
+ | (u & TGEXEC ? S_IXGRP : 0)
+ | (u & TOREAD ? S_IROTH : 0)
+ | (u & TOWRITE ? S_IWOTH : 0)
+ | (u & TOEXEC ? S_IXOTH : 0));
+}
+
+off_t
+off_from_chars (const char *p, size_t s)
+{
+ return from_chars (p, s, "off_t",
+ - (uintmax_t) TYPE_MINIMUM (off_t),
+ (uintmax_t) TYPE_MAXIMUM (off_t));
+}
+
+size_t
+size_from_chars (const char *p, size_t s)
+{
+ return from_chars (p, s, "size_t", (uintmax_t) 0,
+ (uintmax_t) TYPE_MAXIMUM (size_t));
+}
+
+time_t
+time_from_chars (const char *p, size_t s)
+{
+ return from_chars (p, s, "time_t",
+ - (uintmax_t) TYPE_MINIMUM (time_t),
+ (uintmax_t) TYPE_MAXIMUM (time_t));
+}
+
+uid_t
+uid_from_chars (const char *p, size_t s)
+{
+ return from_chars (p, s, "uid_t", (uintmax_t) 0,
+ (uintmax_t) TYPE_MAXIMUM (uid_t));
+}
+
+uintmax_t
+uintmax_from_chars (const char *p, size_t s)
+{
+ return from_chars (p, s, "uintmax_t", (uintmax_t) 0,
+ TYPE_MAXIMUM (uintmax_t));
+}
+
+
+/*----------------------------------------------------------------------.
+| Format O as a null-terminated decimal string into BUF _backwards_; |
+| return pointer to start of result. |
+`----------------------------------------------------------------------*/
+char *
+stringify_uintmax_t_backwards (uintmax_t o, char *buf)
+{
+ *--buf = '\0';
+ do
+ *--buf = '0' + (int) (o % 10);
+ while ((o /= 10) != 0);
+ return buf;
+}
+
+#if !USE_OLD_CTIME
+
+/*-------------------------------------------.
+| Return the time formatted along ISO 8601. |
+`-------------------------------------------*/
+
+/* Also, see http://www.ft.uni-erlangen.de/~mskuhn/iso-time.html. */
+
+static char *
+isotime (const time_t *time)
+{
+ static char buffer[21];
+ struct tm *tm;
+
+ tm = localtime (time);
+ sprintf (buffer, "%4d-%02d-%02d %02d:%02d:%02d\n",
+ tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
+ tm->tm_hour, tm->tm_min, tm->tm_sec);
+ return buffer;
+}
+
+#endif /* not USE_OLD_CTIME */
+
+/*-------------------------------------------------------------------------.
+| Decode MODE from its binary form in a stat structure, and encode it into |
+| a 9 characters string STRING, terminated with a NUL. |
+`-------------------------------------------------------------------------*/
+
+static void
+decode_mode (mode_t mode, char *string)
+{
+ *string++ = mode & S_IRUSR ? 'r' : '-';
+ *string++ = mode & S_IWUSR ? 'w' : '-';
+ *string++ = (mode & S_ISUID
+ ? (mode & S_IXUSR ? 's' : 'S')
+ : (mode & S_IXUSR ? 'x' : '-'));
+ *string++ = mode & S_IRGRP ? 'r' : '-';
+ *string++ = mode & S_IWGRP ? 'w' : '-';
+ *string++ = (mode & S_ISGID
+ ? (mode & S_IXGRP ? 's' : 'S')
+ : (mode & S_IXGRP ? 'x' : '-'));
+ *string++ = mode & S_IROTH ? 'r' : '-';
+ *string++ = mode & S_IWOTH ? 'w' : '-';
+ *string++ = (mode & S_ISVTX
+ ? (mode & S_IXOTH ? 't' : 'T')
+ : (mode & S_IXOTH ? 'x' : '-'));
+ *string = '\0';
+}
+
+/*-------------------------------------------------------------------------.
+| Actually print it. |
+| |
+| Plain and fancy file header block logging. Non-verbose just prints the |
+| name, e.g. for "tar t" or "tar x". This should just contain file names, |
+| so it can be fed back into tar with xargs or the "-T" option. The |
+| verbose option can give a bunch of info, one line per file. I doubt |
+| anybody tries to parse its format, or if they do, they shouldn't. Unix |
+| tar is pretty random here anyway. |
+`-------------------------------------------------------------------------*/
+
+/* FIXME: Note that print_header uses the globals HEAD, HSTAT, and
+ HEAD_STANDARD, which must be set up in advance. Not very clean... */
+
+/* UGSWIDTH starts with 18, so with user and group names <= 8 chars, the
+ columns never shift during the listing. */
+#define UGSWIDTH 18
+static int ugswidth = UGSWIDTH; /* maximum width encountered so far */
+
+/* DATEWIDTH is the number of columns taken by the date and time fields. */
+#if USE_OLD_CDATE
+# define DATEWIDTH 19
+#else
+# define DATEWIDTH 18
+#endif