2 * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 * This code is derived from software contributed to The NetBSD Foundation
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
30 #include <sys/cdefs.h>
33 __RCSID("$NetBSD: stat.c,v 1.13 2003/07/25 03:21:17 atatat Exp $");
37 __FBSDID("$FreeBSD$");
41 #else /* HAVE_CONFIG_H */
42 #define HAVE_STRUCT_STAT_ST_FLAGS 1
43 #define HAVE_STRUCT_STAT_ST_GEN 1
44 #define HAVE_STRUCT_STAT_ST_BIRTHTIME 1
45 #define HAVE_STRUCT_STAT_ST_MTIMENSEC 1
46 #define HAVE_DEVNAME 1
47 #endif /* HAVE_CONFIG_H */
49 #include <sys/param.h>
50 #include <sys/types.h>
65 #if HAVE_STRUCT_STAT_ST_FLAGS
68 #define SHELL_F " st_flags=%f"
69 #else /* HAVE_STRUCT_STAT_ST_FLAGS */
73 #endif /* HAVE_STRUCT_STAT_ST_FLAGS */
75 #if HAVE_STRUCT_STAT_ST_BIRTHTIME
76 #define DEF_B "\"%SB\" "
78 #define SHELL_B "st_birthtime=%B "
79 #else /* HAVE_STRUCT_STAT_ST_BIRTHTIME */
83 #endif /* HAVE_STRUCT_STAT_ST_BIRTHTIME */
85 #if HAVE_STRUCT_STAT_ST_ATIM
86 #define st_atimespec st_atim
87 #define st_ctimespec st_ctim
88 #define st_mtimespec st_mtim
89 #endif /* HAVE_STRUCT_STAT_ST_ATIM */
92 "%d %i %Sp %l %Su %Sg %r %z \"%Sa\" \"%Sm\" \"%Sc\" " DEF_B \
94 #define RAW_FORMAT "%d %i %#p %l %u %g %r %z %a %m %c " RAW_B \
96 #define LS_FORMAT "%Sp %l %Su %Sg %Z %Sm %N%SY"
97 #define LSF_FORMAT "%Sp %l %Su %Sg %Z %Sm %N%T%SY"
98 #define SHELL_FORMAT \
99 "st_dev=%d st_ino=%i st_mode=%#p st_nlink=%l " \
100 "st_uid=%u st_gid=%g st_rdev=%r st_size=%z " \
101 "st_atime=%a st_mtime=%m st_ctime=%c " SHELL_B \
102 "st_blksize=%k st_blocks=%b" SHELL_F
103 #define LINUX_FORMAT \
105 " Size: %-11z FileType: %HT%n" \
106 " Mode: (%OMp%03OLp/%.10Sp) Uid: (%5u/%8Su) Gid: (%5g/%8Sg)%n" \
107 "Device: %Hd,%Ld Inode: %i Links: %l%n" \
112 #define TIME_FORMAT "%b %e %T %Y"
114 #define FLAG_POUND 0x01
115 #define FLAG_SPACE 0x02
116 #define FLAG_PLUS 0x04
117 #define FLAG_ZERO 0x08
118 #define FLAG_MINUS 0x10
121 * These format characters must all be unique, except the magic one.
123 #define FMT_MAGIC '%'
126 #define SIMPLE_NEWLINE 'n'
127 #define SIMPLE_TAB 't'
128 #define SIMPLE_PERCENT '%'
129 #define SIMPLE_NUMBER '@'
131 #define FMT_POUND '#'
132 #define FMT_SPACE ' '
135 #define FMT_MINUS '-'
137 #define FMT_DECIMAL 'D'
138 #define FMT_OCTAL 'O'
139 #define FMT_UNSIGNED 'U'
141 #define FMT_FLOAT 'F'
142 #define FMT_STRING 'S'
144 #define FMTF_DECIMAL 0x01
145 #define FMTF_OCTAL 0x02
146 #define FMTF_UNSIGNED 0x04
147 #define FMTF_HEX 0x08
148 #define FMTF_FLOAT 0x10
149 #define FMTF_STRING 0x20
151 #define HIGH_PIECE 'H'
152 #define MIDDLE_PIECE 'M'
153 #define LOW_PIECE 'L'
155 #define SHOW_st_dev 'd'
156 #define SHOW_st_ino 'i'
157 #define SHOW_st_mode 'p'
158 #define SHOW_st_nlink 'l'
159 #define SHOW_st_uid 'u'
160 #define SHOW_st_gid 'g'
161 #define SHOW_st_rdev 'r'
162 #define SHOW_st_atime 'a'
163 #define SHOW_st_mtime 'm'
164 #define SHOW_st_ctime 'c'
165 #define SHOW_st_btime 'B'
166 #define SHOW_st_size 'z'
167 #define SHOW_st_blocks 'b'
168 #define SHOW_st_blksize 'k'
169 #define SHOW_st_flags 'f'
170 #define SHOW_st_gen 'v'
171 #define SHOW_symlink 'Y'
172 #define SHOW_filetype 'T'
173 #define SHOW_filename 'N'
174 #define SHOW_sizerdev 'Z'
176 void usage(const char *);
177 void output(const struct stat *, const char *,
178 const char *, int, int, int);
179 int format1(const struct stat *, /* stat info */
180 const char *, /* the file name */
181 const char *, int, /* the format string itself */
182 char *, size_t, /* a place to put the output */
183 int, int, int, int, /* the parsed format */
185 #if HAVE_STRUCT_STAT_ST_FLAGS
186 char *xfflagstostr(unsigned long);
192 #define addchar(s, c, nl) \
194 (void)fputc((c), (s)); \
195 (*nl) = ((c) == '\n'); \
196 } while (0/*CONSTCOND*/)
199 main(int argc, char *argv[])
202 int ch, rc, errs, am_readlink;
203 int lsF, fmtchar, usestat, fn, nonl, quiet;
204 char *statfmt, *options, *synopsis;
205 char dname[sizeof _PATH_DEV + SPECNAMELEN] = _PATH_DEV;
218 if (strcmp(getprogname(), "readlink") == 0) {
221 synopsis = "[-n] [file ...]";
226 options = "f:FlLnqrst:x";
227 synopsis = "[-FlLnqrsx] [-f format] [-t timefmt] [file ...]";
230 while ((ch = getopt(argc, argv, options)) != -1)
252 errx(1, "can't use format '%c' with '%c'",
267 if (fmtchar == '\0') {
272 statfmt = DEF_FORMAT;
276 if (lsF && fmtchar != 'l')
277 errx(1, "can't use format '%c' with -F", fmtchar);
281 /* statfmt already set */
284 statfmt = lsF ? LSF_FORMAT : LS_FORMAT;
287 statfmt = RAW_FORMAT;
290 statfmt = SHELL_FORMAT;
293 statfmt = LINUX_FORMAT;
303 timefmt = TIME_FORMAT;
308 if (fdevname_r(STDIN_FILENO, dname +
309 sizeof _PATH_DEV - 1, SPECNAMELEN) != NULL)
313 rc = fstat(STDIN_FILENO, &st);
317 rc = stat(file, &st);
319 rc = lstat(file, &st);
326 warn("%s: stat", file);
329 output(&st, file, statfmt, fn, nonl, quiet);
336 return (am_readlink ? linkfail : errs);
339 #if HAVE_STRUCT_STAT_ST_FLAGS
341 * fflagstostr() wrapper that leaks only once
344 xfflagstostr(unsigned long fflags)
346 static char *str = NULL;
351 str = fflagstostr(fflags);
353 err(1, "fflagstostr");
356 #endif /* HAVE_STRUCT_STAT_ST_FLAGS */
359 usage(const char *synopsis)
362 (void)fprintf(stderr, "usage: %s %s\n", getprogname(), synopsis);
367 * Parses a format string.
370 output(const struct stat *st, const char *file,
371 const char *statfmt, int fn, int nonl, int quiet)
373 int flags, size, prec, ofmt, hilo, what;
379 while (*statfmt != '\0') {
382 * Non-format characters go straight out.
384 if (*statfmt != FMT_MAGIC) {
385 addchar(stdout, *statfmt, &nl);
391 * The current format "substring" starts here,
392 * and then we skip the magic.
398 * Some simple one-character "formats".
402 addchar(stdout, '\n', &nl);
406 addchar(stdout, '\t', &nl);
410 addchar(stdout, '%', &nl);
413 case SIMPLE_NUMBER: {
416 snprintf(num, sizeof(num), "%d", fn);
417 for (p = &num[0]; *p; p++)
418 addchar(stdout, *p, &nl);
425 * This must be an actual format string. Format strings are
426 * similar to printf(3) formats up to a point, and are of
429 * % required start of format
430 * [-# +0] opt. format characters
431 * size opt. field width
432 * . opt. decimal separator, followed by
433 * prec opt. precision
434 * fmt opt. output specifier (string, numeric, etc.)
435 * sub opt. sub field specifier (high, middle, low)
436 * datum required field specifier (size, mode, etc)
438 * Only the % and the datum selector are required. All data
439 * have reasonable default output forms. The "sub" specifier
440 * only applies to certain data (mode, dev, rdev, filetype).
441 * The symlink output defaults to STRING, yet will only emit
442 * the leading " -> " if STRING is explicitly specified. The
443 * sizerdev datum will generate rdev output for character or
444 * block devices, and size output for all others.
448 if (*statfmt == FMT_POUND)
450 else if (*statfmt == FMT_SPACE)
452 else if (*statfmt == FMT_PLUS)
454 else if (*statfmt == FMT_ZERO)
456 else if (*statfmt == FMT_MINUS)
461 } while (1/*CONSTCOND*/);
464 if (isdigit((unsigned)*statfmt)) {
466 while (isdigit((unsigned)*statfmt)) {
467 size = (size * 10) + (*statfmt - '0');
475 if (*statfmt == FMT_DOT) {
479 while (isdigit((unsigned)*statfmt)) {
480 prec = (prec * 10) + (*statfmt - '0');
487 #define fmtcase(x, y) case (y): (x) = (y); statfmt++; break
488 #define fmtcasef(x, y, z) case (y): (x) = (z); statfmt++; break
490 fmtcasef(ofmt, FMT_DECIMAL, FMTF_DECIMAL);
491 fmtcasef(ofmt, FMT_OCTAL, FMTF_OCTAL);
492 fmtcasef(ofmt, FMT_UNSIGNED, FMTF_UNSIGNED);
493 fmtcasef(ofmt, FMT_HEX, FMTF_HEX);
494 fmtcasef(ofmt, FMT_FLOAT, FMTF_FLOAT);
495 fmtcasef(ofmt, FMT_STRING, FMTF_STRING);
502 fmtcase(hilo, HIGH_PIECE);
503 fmtcase(hilo, MIDDLE_PIECE);
504 fmtcase(hilo, LOW_PIECE);
511 fmtcase(what, SHOW_st_dev);
512 fmtcase(what, SHOW_st_ino);
513 fmtcase(what, SHOW_st_mode);
514 fmtcase(what, SHOW_st_nlink);
515 fmtcase(what, SHOW_st_uid);
516 fmtcase(what, SHOW_st_gid);
517 fmtcase(what, SHOW_st_rdev);
518 fmtcase(what, SHOW_st_atime);
519 fmtcase(what, SHOW_st_mtime);
520 fmtcase(what, SHOW_st_ctime);
521 fmtcase(what, SHOW_st_btime);
522 fmtcase(what, SHOW_st_size);
523 fmtcase(what, SHOW_st_blocks);
524 fmtcase(what, SHOW_st_blksize);
525 fmtcase(what, SHOW_st_flags);
526 fmtcase(what, SHOW_st_gen);
527 fmtcase(what, SHOW_symlink);
528 fmtcase(what, SHOW_filetype);
529 fmtcase(what, SHOW_filename);
530 fmtcase(what, SHOW_sizerdev);
539 subfmt, statfmt - subfmt,
541 flags, size, prec, ofmt, hilo, what);
543 for (i = 0; i < t && i < sizeof(buf); i++)
544 addchar(stdout, buf[i], &nl);
549 errx(1, "%.*s: bad format",
550 (int)(statfmt - subfmt + 1), subfmt);
554 (void)fputc('\n', stdout);
555 (void)fflush(stdout);
559 * Arranges output according to a single parsed format substring.
562 format1(const struct stat *st,
564 const char *fmt, int flen,
565 char *buf, size_t blen,
566 int flags, int size, int prec, int ofmt,
570 char *sdata, lfmt[24], tmp[20];
571 char smode[12], sid[12], path[PATH_MAX + 4];
574 const struct timespec *tsp;
577 int l, small, formats;
584 * First, pick out the data and tweak it based on hilo or
585 * specified output format (symlink output only).
590 small = (sizeof(st->st_dev) == 4);
591 data = (what == SHOW_st_dev) ? st->st_dev : st->st_rdev;
593 sdata = (what == SHOW_st_dev) ?
594 devname(st->st_dev, S_IFBLK) :
596 S_ISCHR(st->st_mode) ? S_IFCHR :
597 S_ISBLK(st->st_mode) ? S_IFBLK :
601 #endif /* HAVE_DEVNAME */
602 if (hilo == HIGH_PIECE) {
606 else if (hilo == LOW_PIECE) {
607 data = minor((unsigned)data);
610 formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX |
613 #else /* HAVE_DEVNAME */
615 #endif /* HAVE_DEVNAME */
617 ofmt = FMTF_UNSIGNED;
620 small = (sizeof(st->st_ino) == 4);
623 formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX;
625 ofmt = FMTF_UNSIGNED;
628 small = (sizeof(st->st_mode) == 4);
630 strmode(st->st_mode, smode);
633 if (sdata[l - 1] == ' ')
635 if (hilo == HIGH_PIECE) {
641 else if (hilo == MIDDLE_PIECE) {
642 data = (data >> 9) & 07;
647 else if (hilo == LOW_PIECE) {
653 formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX |
659 small = (sizeof(st->st_dev) == 4);
662 formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX;
664 ofmt = FMTF_UNSIGNED;
667 small = (sizeof(st->st_uid) == 4);
669 if ((pw = getpwuid(st->st_uid)) != NULL)
672 snprintf(sid, sizeof(sid), "(%ld)", (long)st->st_uid);
675 formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX |
678 ofmt = FMTF_UNSIGNED;
681 small = (sizeof(st->st_gid) == 4);
683 if ((gr = getgrgid(st->st_gid)) != NULL)
686 snprintf(sid, sizeof(sid), "(%ld)", (long)st->st_gid);
689 formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX |
692 ofmt = FMTF_UNSIGNED;
695 tsp = &st->st_atimespec;
699 tsp = &st->st_mtimespec;
703 tsp = &st->st_ctimespec;
705 #if HAVE_STRUCT_STAT_ST_BIRTHTIME
708 tsp = &st->st_birthtimespec;
709 #endif /* HAVE_STRUCT_STAT_ST_BIRTHTIME */
710 ts = *tsp; /* copy so we can muck with it */
711 small = (sizeof(ts.tv_sec) == 4);
714 tm = localtime(&ts.tv_sec);
715 (void)strftime(path, sizeof(path), timefmt, tm);
717 formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX |
718 FMTF_FLOAT | FMTF_STRING;
723 small = (sizeof(st->st_size) == 4);
726 formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX;
728 ofmt = FMTF_UNSIGNED;
731 small = (sizeof(st->st_blocks) == 4);
732 data = st->st_blocks;
734 formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX;
736 ofmt = FMTF_UNSIGNED;
738 case SHOW_st_blksize:
739 small = (sizeof(st->st_blksize) == 4);
740 data = st->st_blksize;
742 formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX;
744 ofmt = FMTF_UNSIGNED;
746 #if HAVE_STRUCT_STAT_ST_FLAGS
748 small = (sizeof(st->st_flags) == 4);
750 sdata = xfflagstostr(st->st_flags);
753 formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX |
756 ofmt = FMTF_UNSIGNED;
758 #endif /* HAVE_STRUCT_STAT_ST_FLAGS */
759 #if HAVE_STRUCT_STAT_ST_GEN
761 small = (sizeof(st->st_gen) == 4);
764 formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX;
766 ofmt = FMTF_UNSIGNED;
768 #endif /* HAVE_STRUCT_STAT_ST_GEN */
772 if (S_ISLNK(st->st_mode)) {
773 snprintf(path, sizeof(path), " -> ");
774 l = readlink(file, path + 4, sizeof(path) - 4 - 1);
781 sdata = path + (ofmt == FMTF_STRING ? 0 : 4);
787 formats = FMTF_STRING;
796 if (hilo == 0 || hilo == LOW_PIECE) {
797 switch (st->st_mode & S_IFMT) {
798 case S_IFIFO: (void)strcat(sdata, "|"); break;
799 case S_IFDIR: (void)strcat(sdata, "/"); break;
802 (S_IXUSR | S_IXGRP | S_IXOTH))
803 (void)strcat(sdata, "*");
805 case S_IFLNK: (void)strcat(sdata, "@"); break;
806 case S_IFSOCK: (void)strcat(sdata, "="); break;
808 case S_IFWHT: (void)strcat(sdata, "%"); break;
811 case S_IFDOOR: (void)strcat(sdata, ">"); break;
812 #endif /* S_IFDOOR */
816 else if (hilo == HIGH_PIECE) {
817 switch (st->st_mode & S_IFMT) {
818 case S_IFIFO: sdata = "Fifo File"; break;
819 case S_IFCHR: sdata = "Character Device"; break;
820 case S_IFDIR: sdata = "Directory"; break;
821 case S_IFBLK: sdata = "Block Device"; break;
822 case S_IFREG: sdata = "Regular File"; break;
823 case S_IFLNK: sdata = "Symbolic Link"; break;
824 case S_IFSOCK: sdata = "Socket"; break;
826 case S_IFWHT: sdata = "Whiteout File"; break;
829 case S_IFDOOR: sdata = "Door"; break;
830 #endif /* S_IFDOOR */
831 default: sdata = "???"; break;
835 formats = FMTF_STRING;
842 (void)strncpy(path, file, sizeof(path));
844 formats = FMTF_STRING;
849 if (S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode)) {
850 char majdev[20], mindev[20];
856 majdev, sizeof(majdev),
858 ofmt, HIGH_PIECE, SHOW_st_rdev);
862 mindev, sizeof(mindev),
864 ofmt, LOW_PIECE, SHOW_st_rdev);
865 return (snprintf(buf, blen, "%.*s,%.*s",
866 l1, majdev, l2, mindev));
874 ofmt, 0, SHOW_st_size));
878 errx(1, "%.*s: bad format", (int)flen, fmt);
882 * If a subdatum was specified but not supported, or an output
883 * format was selected that is not supported, that's an error.
885 if (hilo != 0 || (ofmt & formats) == 0)
886 errx(1, "%.*s: bad format", (int)flen, fmt);
889 * Assemble the format string for passing to printf(3).
892 (void)strcat(lfmt, "%");
893 if (flags & FLAG_POUND)
894 (void)strcat(lfmt, "#");
895 if (flags & FLAG_SPACE)
896 (void)strcat(lfmt, " ");
897 if (flags & FLAG_PLUS)
898 (void)strcat(lfmt, "+");
899 if (flags & FLAG_MINUS)
900 (void)strcat(lfmt, "-");
901 if (flags & FLAG_ZERO)
902 (void)strcat(lfmt, "0");
905 * Only the timespecs support the FLOAT output format, and that
906 * requires work that differs from the other formats.
908 if (ofmt == FMTF_FLOAT) {
910 * Nothing after the decimal point, so just print seconds.
914 (void)snprintf(tmp, sizeof(tmp), "%d", size);
915 (void)strcat(lfmt, tmp);
917 (void)strcat(lfmt, "d");
918 return (snprintf(buf, blen, lfmt, ts.tv_sec));
922 * Unspecified precision gets all the precision we have:
929 * Adjust the size for the decimal point and the digits
935 * Any leftover size that's legitimate will be used.
938 (void)snprintf(tmp, sizeof(tmp), "%d", size);
939 (void)strcat(lfmt, tmp);
941 (void)strcat(lfmt, "d");
944 * The stuff after the decimal point always needs zero
947 (void)strcat(lfmt, ".%0");
950 * We can "print" at most nine digits of precision. The
951 * rest we will pad on at the end.
953 (void)snprintf(tmp, sizeof(tmp), "%dd", prec > 9 ? 9 : prec);
954 (void)strcat(lfmt, tmp);
957 * For precision of less that nine digits, trim off the
958 * less significant figures.
960 for (; prec < 9; prec++)
964 * Use the format, and then tack on any zeroes that
965 * might be required to make up the requested precision.
967 l = snprintf(buf, blen, lfmt, ts.tv_sec, ts.tv_nsec);
968 for (; prec > 9 && l < blen; prec--, l++)
969 (void)strcat(buf, "0");
974 * Add on size and precision, if specified, to the format.
977 (void)snprintf(tmp, sizeof(tmp), "%d", size);
978 (void)strcat(lfmt, tmp);
981 (void)snprintf(tmp, sizeof(tmp), ".%d", prec);
982 (void)strcat(lfmt, tmp);
986 * String output uses the temporary sdata.
988 if (ofmt == FMTF_STRING) {
990 errx(1, "%.*s: bad format", (int)flen, fmt);
991 (void)strcat(lfmt, "s");
992 return (snprintf(buf, blen, lfmt, sdata));
996 * Ensure that sign extension does not cause bad looking output
999 if (small && ofmt != FMTF_DECIMAL)
1000 data = (u_int32_t)data;
1003 * The four "numeric" output forms.
1005 (void)strcat(lfmt, "ll");
1007 case FMTF_DECIMAL: (void)strcat(lfmt, "d"); break;
1008 case FMTF_OCTAL: (void)strcat(lfmt, "o"); break;
1009 case FMTF_UNSIGNED: (void)strcat(lfmt, "u"); break;
1010 case FMTF_HEX: (void)strcat(lfmt, "x"); break;
1013 return (snprintf(buf, blen, lfmt, data));