More properly host-tool-ify stat

This commit is contained in:
atatat 2003-07-25 03:21:15 +00:00
parent e8876f361f
commit d5fb781871
5 changed files with 76 additions and 19 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: strmode.c,v 1.13 2002/01/31 22:43:41 tv Exp $ */
/* $NetBSD: strmode.c,v 1.14 2003/07/25 03:21:18 atatat Exp $ */
/*-
* Copyright (c) 1990, 1993
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)strmode.c 8.3 (Berkeley) 8/15/94";
#else
__RCSID("$NetBSD: strmode.c,v 1.13 2002/01/31 22:43:41 tv Exp $");
__RCSID("$NetBSD: strmode.c,v 1.14 2003/07/25 03:21:18 atatat Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@ -96,6 +96,11 @@ strmode(mode, p)
case S_IFWHT: /* whiteout */
*p++ = 'w';
break;
#endif
#ifdef S_IFDOOR
case S_IFDOOR: /* door */
*p++ = 'D';
break;
#endif
default: /* unknown */
*p++ = '?';

View File

@ -1,4 +1,4 @@
/* $NetBSD: config.h.in,v 1.29 2003/07/18 13:45:15 fredb Exp $ */
/* $NetBSD: config.h.in,v 1.30 2003/07/25 03:21:16 atatat Exp $ */
#ifndef __NETBSD_COMPAT_CONFIG_H__
#define __NETBSD_COMPAT_CONFIG_H__
@ -40,6 +40,8 @@
#undef HAVE_STRUCT_DIRENT_D_NAMLEN
#undef HAVE_STRUCT_STAT_ST_FLAGS
#undef HAVE_STRUCT_STAT_ST_GEN
#undef HAVE_STRUCT_STAT_ST_BIRTHTIME
#undef HAVE_STRUCT_STAT_ST_ATIM
#undef HAVE_STRUCT_STAT_ST_MTIMENSEC
#undef HAVE_STRUCT_STATFS_F_IOSIZE
@ -51,6 +53,7 @@
#undef HAVE_ASNPRINTF
#undef HAVE_BASENAME
#undef HAVE_CGETNEXT
#undef HAVE_DEVNAME
#undef HAVE_DIRFD
#undef HAVE_DIRNAME
#undef HAVE_FGETLN

View File

@ -1,4 +1,4 @@
# $NetBSD: configure.ac,v 1.38 2003/07/18 13:45:16 fredb Exp $
# $NetBSD: configure.ac,v 1.39 2003/07/25 03:21:15 atatat Exp $
#
# Autoconf definition file for libnbcompat.
#
@ -83,6 +83,7 @@ AC_CHECK_MEMBERS([DIR.dd_fd, struct dirent.d_namlen],,,
[#include <sys/types.h>
#include <dirent.h>])
AC_CHECK_MEMBERS([struct stat.st_flags, struct stat.st_gen,
struct stat.st_birthtime, struct stat.st_atim,
struct stat.st_mtimensec],,, [#include <sys/stat.h>])
AC_CHECK_MEMBERS(struct statfs.f_iosize,,, [#include <sys/mount.h>])
@ -96,7 +97,7 @@ AC_CHECK_DECLS(sys_signame,,, [#include <signal.h>])
# Library functions (where a .h check isn't enough).
AC_FUNC_ALLOCA
AC_CHECK_FUNCS(atoll asprintf asnprintf basename dirfd dirname \
AC_CHECK_FUNCS(atoll asprintf asnprintf basename devname dirfd dirname \
fgetln flock fparseln futimes getopt getopt_long \
isblank issetugid lchflags lchmod lchown lutimes mkstemp mkdtemp \
poll pread putc_unlocked pwcache_userdb pwrite random setenv \

View File

@ -1,12 +1,10 @@
# $NetBSD: Makefile,v 1.6 2003/07/22 13:58:49 lukem Exp $
# $NetBSD: Makefile,v 1.7 2003/07/25 03:21:17 atatat Exp $
PROG= stat
.if !defined(HOSTPROG)
LINKS= ${BINDIR}/stat ${BINDIR}/readlink
MLINKS= stat.1 readlink.1
.else
CPPFLAGS+=-DHOSTPROG
.endif
.include <bsd.prog.mk>

View File

@ -1,4 +1,4 @@
/* $NetBSD: stat.c,v 1.12 2003/07/23 07:23:23 lukem Exp $ */
/* $NetBSD: stat.c,v 1.13 2003/07/25 03:21:17 atatat Exp $ */
/*
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -38,14 +38,18 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: stat.c,v 1.12 2003/07/23 07:23:23 lukem Exp $");
__RCSID("$NetBSD: stat.c,v 1.13 2003/07/25 03:21:17 atatat Exp $");
#endif
#if HAVE_CONFIG_H
#include "config.h"
#else
#else /* HAVE_CONFIG_H */
#define HAVE_STRUCT_STAT_ST_FLAGS 1
#endif
#define HAVE_STRUCT_STAT_ST_GEN 1
#define HAVE_STRUCT_STAT_ST_BIRTHTIME 1
#define HAVE_STRUCT_STAT_ST_MTIMENSEC 1
#define HAVE_DEVNAME 1
#endif /* HAVE_CONFIG_H */
#include <sys/types.h>
#include <sys/stat.h>
@ -61,16 +65,44 @@ __RCSID("$NetBSD: stat.c,v 1.12 2003/07/23 07:23:23 lukem Exp $");
#include <time.h>
#include <unistd.h>
#if HAVE_STRUCT_STAT_ST_FLAGS
#define DEF_F "%#Xf "
#define RAW_F "%f "
#define SHELL_F " st_flags=%f"
#else /* HAVE_STRUCT_STAT_ST_FLAGS */
#define DEF_F
#define RAW_F
#define SHELL_F
#endif /* HAVE_STRUCT_STAT_ST_FLAGS */
#if HAVE_STRUCT_STAT_ST_BIRTHTIME
#define DEF_B "\"%SB\" "
#define RAW_B "%B "
#define SHELL_B "st_birthtime=%B "
#else /* HAVE_STRUCT_STAT_ST_BIRTHTIME */
#define DEF_B
#define RAW_B
#define SHELL_B
#endif /* HAVE_STRUCT_STAT_ST_BIRTHTIME */
#if HAVE_STRUCT_STAT_ST_ATIM
#define st_atimespec st_atim
#define st_ctimespec st_ctim
#define st_mtimespec st_mtim
#endif /* HAVE_STRUCT_STAT_ST_ATIM */
#define DEF_FORMAT \
"%d %i %Sp %l %Su %Sg %r %z \"%Sa\" \"%Sm\" \"%Sc\" %k %b %N"
#define RAW_FORMAT "%d %i %#p %l %u %g %r %z %a %m %c %k %b %N"
"%d %i %Sp %l %Su %Sg %r %z \"%Sa\" \"%Sm\" \"%Sc\" " DEF_B \
"%k %b " DEF_F "%N"
#define RAW_FORMAT "%d %i %#p %l %u %g %r %z %a %m %c " RAW_B \
"%k %b " RAW_F "%N"
#define LS_FORMAT "%Sp %l %Su %Sg %Z %Sm %N%SY"
#define LSF_FORMAT "%Sp %l %Su %Sg %Z %Sm %N%T%SY"
#define SHELL_FORMAT \
"st_dev=%d st_ino=%i st_mode=%#p st_nlink=%l " \
"st_uid=%u st_gid=%g st_rdev=%r st_size=%z " \
"st_atime=%a st_mtime=%m st_ctime=%c " \
"st_blksize=%k st_blocks=%b"
"st_atime=%a st_mtime=%m st_ctime=%c " SHELL_B \
"st_blksize=%k st_blocks=%b" SHELL_F
#define LINUX_FORMAT \
" File: \"%N\"%n" \
" Size: %-11z FileType: %HT%n" \
@ -529,6 +561,7 @@ format1(const struct stat *st,
case SHOW_st_rdev:
small = (sizeof(st->st_dev) == 4);
data = (what == SHOW_st_dev) ? st->st_dev : st->st_rdev;
#if HAVE_DEVNAME
sdata = (what == SHOW_st_dev) ?
devname(st->st_dev, S_IFBLK) :
devname(st->st_rdev,
@ -537,6 +570,7 @@ format1(const struct stat *st,
0U);
if (sdata == NULL)
sdata = "???";
#endif /* HAVE_DEVNAME */
if (hilo == HIGH_PIECE) {
data = major(data);
hilo = 0;
@ -546,7 +580,11 @@ format1(const struct stat *st,
hilo = 0;
}
formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX |
#if HAVE_DEVNAME
FMTF_STRING;
#else /* HAVE_DEVNAME */
0;
#endif /* HAVE_DEVNAME */
if (ofmt == 0)
ofmt = FMTF_UNSIGNED;
break;
@ -636,11 +674,11 @@ format1(const struct stat *st,
if (tsp == NULL)
tsp = &st->st_ctimespec;
/* FALLTHROUGH */
#if !defined(HOSTPROG)
#if HAVE_STRUCT_STAT_ST_BIRTHTIME
case SHOW_st_btime:
if (tsp == NULL)
tsp = &st->st_birthtimespec;
#endif
#endif /* HAVE_STRUCT_STAT_ST_BIRTHTIME */
ts = *tsp; /* copy so we can muck with it */
small = (sizeof(ts.tv_sec) == 4);
data = ts.tv_sec;
@ -686,7 +724,8 @@ format1(const struct stat *st,
if (ofmt == 0)
ofmt = FMTF_UNSIGNED;
break;
#endif
#endif /* HAVE_STRUCT_STAT_ST_FLAGS */
#if HAVE_STRUCT_STAT_ST_GEN
case SHOW_st_gen:
small = (sizeof(st->st_gen) == 4);
data = st->st_gen;
@ -695,6 +734,7 @@ format1(const struct stat *st,
if (ofmt == 0)
ofmt = FMTF_UNSIGNED;
break;
#endif /* HAVE_STRUCT_STAT_ST_GEN */
case SHOW_symlink:
small = 0;
data = 0;
@ -733,7 +773,12 @@ format1(const struct stat *st,
break;
case S_IFLNK: (void)strcat(sdata, "@"); break;
case S_IFSOCK: (void)strcat(sdata, "="); break;
#ifdef S_IFWHT
case S_IFWHT: (void)strcat(sdata, "%"); break;
#endif /* S_IFWHT */
#ifdef S_IFDOOR
case S_IFDOOR: (void)strcat(sdata, ">"); break;
#endif /* S_IFDOOR */
}
hilo = 0;
}
@ -746,7 +791,12 @@ format1(const struct stat *st,
case S_IFREG: sdata = "Regular File"; break;
case S_IFLNK: sdata = "Symbolic Link"; break;
case S_IFSOCK: sdata = "Socket"; break;
#ifdef S_IFWHT
case S_IFWHT: sdata = "Whiteout File"; break;
#endif /* S_IFWHT */
#ifdef S_IFDOOR
case S_IFDOOR: sdata = "Door"; break;
#endif /* S_IFDOOR */
default: sdata = "???"; break;
}
hilo = 0;