Print this page
2990 file(1) should have a -s flag to process special files
@@ -28,10 +28,14 @@
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
+/*
+ * Copyright 2012, Josef 'Jeff' Sipek <jeffpc@31bits.net>. All rights reserved.
+ */
+
#define _LARGEFILE64_SOURCE
/* Get definitions for the relocation types supported. */
#define ELF_TARGET_ALL
@@ -139,10 +143,11 @@
static int i; /* global index into first 'fbsz' bytes of file */
static int fbsz;
static int ifd = -1;
static int elffd = -1;
static int tret;
+static int sflg;
static int hflg;
static int dflg;
static int mflg;
static int M_flg;
static int iflg;
@@ -216,11 +221,11 @@
#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
#define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */
#endif
(void) textdomain(TEXT_DOMAIN);
- while ((ch = getopt(argc, argv, "M:cdf:him:")) != EOF) {
+ while ((ch = getopt(argc, argv, "M:cdsf:him:")) != EOF) {
switch (ch) {
case 'M':
add_to_mlist(optarg, !dflg);
M_flg++;
@@ -236,10 +241,14 @@
add_to_mlist(dfile, 0);
dflg++;
}
break;
+ case 's':
+ sflg++;
+ break;
+
case 'f':
fflg++;
errno = 0;
if ((fl = fopen(optarg, "r")) == NULL) {
int err = errno;
@@ -289,10 +298,12 @@
usage();
}
if (iflg && cflg) {
usage();
}
+ if (sflg && (iflg || cflg))
+ usage();
if (!dflg && !mflg && !M_flg && !iflg) {
/* no -d, -m, nor -M option; also -i option doesn't need magic */
default_magic();
if (f_mkmtab(dfile, cflg, 0) == -1) {
@@ -456,10 +467,12 @@
(void) printf(gettext("regular file\n"));
return (0);
}
break;
case S_IFCHR:
+ if (sflg)
+ break;
(void) printf(gettext("character"));
goto spcl;
case S_IFDIR:
(void) printf(gettext("directory\n"));
@@ -479,10 +492,12 @@
buf[cc] = '\0';
(void) printf(gettext("symbolic link to %s\n"), buf);
return (0);
case S_IFBLK:
+ if (sflg)
+ break;
(void) printf(gettext("block"));
/* major and minor, see sys/mkdev.h */
spcl:
(void) printf(gettext(" special (%d/%d)\n"),
major(mbuf.st_rdev), minor(mbuf.st_rdev));
@@ -1643,12 +1658,12 @@
static void
usage(void)
{
(void) fprintf(stderr, gettext(
- "usage: file [-dh] [-M mfile] [-m mfile] [-f ffile] file ...\n"
- " file [-dh] [-M mfile] [-m mfile] -f ffile\n"
+ "usage: file [-dhs] [-M mfile] [-m mfile] [-f ffile] file ...\n"
+ " file [-dhs] [-M mfile] [-m mfile] -f ffile\n"
" file -i [-h] [-f ffile] file ...\n"
" file -i [-h] -f ffile\n"
" file -c [-d] [-M mfile] [-m mfile]\n"));
exit(2);
}