Print this page
2990 file(1) should have a -s flag to process special files

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/file/file.c
          +++ new/usr/src/cmd/file/file.c
↓ open down ↓ 22 lines elided ↑ open up ↑
  23   23  
  24   24  
  25   25  /*      Copyright (c) 1987, 1988 Microsoft Corporation  */
  26   26  /*        All Rights Reserved   */
  27   27  
  28   28  /*
  29   29   * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  30   30   * Use is subject to license terms.
  31   31   */
  32   32  
       33 +/*
       34 + * Copyright 2012, Josef 'Jeff' Sipek <jeffpc@31bits.net>. All rights reserved.
       35 + */
       36 +
  33   37  #define _LARGEFILE64_SOURCE
  34   38  
  35   39  /* Get definitions for the relocation types supported. */
  36   40  #define ELF_TARGET_ALL
  37   41  
  38   42  #include <ctype.h>
  39   43  #include <unistd.h>
  40   44  #include <fcntl.h>
  41   45  #include <signal.h>
  42   46  #include <stdio.h>
↓ open down ↓ 91 lines elided ↑ open up ↑
 134  138  static wchar_t  wchar;
 135  139  static int      length;
 136  140  static int      IS_ascii;
 137  141  static int      Max;
 138  142  /* end for MB env */
 139  143  static int      i;      /* global index into first 'fbsz' bytes of file */
 140  144  static int      fbsz;
 141  145  static int      ifd = -1;
 142  146  static int      elffd = -1;
 143  147  static int      tret;
      148 +static int      sflg;
 144  149  static int      hflg;
 145  150  static int      dflg;
 146  151  static int      mflg;
 147  152  static int      M_flg;
 148  153  static int      iflg;
 149  154  static struct stat64    mbuf;
 150  155  
 151  156  static char     **mlist1;       /* 1st ordered list of magic files */
 152  157  static char     **mlist2;       /* 2nd ordered list of magic files */
 153  158  static size_t   mlist1_sz;      /* number of ptrs allocated for mlist1 */
↓ open down ↓ 57 lines elided ↑ open up ↑
 211  216          char    *ap = NULL;
 212  217          int     pathlen;
 213  218          char    **filep;
 214  219  
 215  220          (void) setlocale(LC_ALL, "");
 216  221  #if !defined(TEXT_DOMAIN)       /* Should be defined by cc -D */
 217  222  #define TEXT_DOMAIN "SYS_TEST"  /* Use this only if it weren't */
 218  223  #endif
 219  224          (void) textdomain(TEXT_DOMAIN);
 220  225  
 221      -        while ((ch = getopt(argc, argv, "M:cdf:him:")) != EOF) {
      226 +        while ((ch = getopt(argc, argv, "M:cdsf:him:")) != EOF) {
 222  227                  switch (ch) {
 223  228  
 224  229                  case 'M':
 225  230                          add_to_mlist(optarg, !dflg);
 226  231                          M_flg++;
 227  232                          break;
 228  233  
 229  234                  case 'c':
 230  235                          cflg++;
 231  236                          break;
 232  237  
 233  238                  case 'd':
 234  239                          if (!dflg) {
 235  240                                  default_magic();
 236  241                                  add_to_mlist(dfile, 0);
 237  242                                  dflg++;
 238  243                          }
 239  244                          break;
 240  245  
      246 +                case 's':
      247 +                        sflg++;
      248 +                        break;
      249 +
 241  250                  case 'f':
 242  251                          fflg++;
 243  252                          errno = 0;
 244  253                          if ((fl = fopen(optarg, "r")) == NULL) {
 245  254                                  int err = errno;
 246  255                                  (void) fprintf(stderr, gettext("%s: cannot "
 247  256                                      "open file %s: %s\n"), File, optarg,
 248  257                                      err ? strerror(err) : "");
 249  258                                  usage();
 250  259                          }
↓ open down ↓ 33 lines elided ↑ open up ↑
 284  293                  }
 285  294          }
 286  295          if (!cflg && !fflg && (eflg || optind == argc))
 287  296                  usage();
 288  297          if (iflg && (dflg || mflg || M_flg)) {
 289  298                  usage();
 290  299          }
 291  300          if (iflg && cflg) {
 292  301                  usage();
 293  302          }
      303 +        if (sflg && (iflg || cflg))
      304 +                usage();
 294  305  
 295  306          if (!dflg && !mflg && !M_flg && !iflg) {
 296  307          /* no -d, -m, nor -M option; also -i option doesn't need magic  */
 297  308                  default_magic();
 298  309                  if (f_mkmtab(dfile, cflg, 0) == -1) {
 299  310                          exit(2);
 300  311                  }
 301  312          }
 302  313  
 303  314          else if (mflg && !M_flg && !dflg) {
↓ open down ↓ 147 lines elided ↑ open up ↑
 451  462                  }
 452  463          }
 453  464          switch (mbuf.st_mode & S_IFMT) {
 454  465          case S_IFREG:
 455  466                  if (iflg) {
 456  467                          (void) printf(gettext("regular file\n"));
 457  468                          return (0);
 458  469                  }
 459  470                  break;
 460  471          case S_IFCHR:
      472 +                if (sflg)
      473 +                        break;
 461  474                  (void) printf(gettext("character"));
 462  475                  goto spcl;
 463  476  
 464  477          case S_IFDIR:
 465  478                  (void) printf(gettext("directory\n"));
 466  479                  return (0);
 467  480  
 468  481          case S_IFIFO:
 469  482                  (void) printf(gettext("fifo\n"));
 470  483                  return (0);
↓ open down ↓ 3 lines elided ↑ open up ↑
 474  487                          int err = errno;
 475  488                          (void) printf(gettext("readlink error: %s\n"),
 476  489                              strerror(err));
 477  490                          return (1);
 478  491                  }
 479  492                  buf[cc] = '\0';
 480  493                  (void) printf(gettext("symbolic link to %s\n"), buf);
 481  494                  return (0);
 482  495  
 483  496          case S_IFBLK:
      497 +                if (sflg)
      498 +                        break;
 484  499                  (void) printf(gettext("block"));
 485  500                                          /* major and minor, see sys/mkdev.h */
 486  501  spcl:
 487  502                  (void) printf(gettext(" special (%d/%d)\n"),
 488  503                      major(mbuf.st_rdev), minor(mbuf.st_rdev));
 489  504                  return (0);
 490  505  
 491  506          case S_IFSOCK:
 492  507                  (void) printf("socket\n");
 493  508                  /* FIXME, should open and try to getsockname. */
↓ open down ↓ 1144 lines elided ↑ open up ↑
1638 1653          } else {
1639 1654                  (void) printf(gettext("SunOS %u-bit %s crash dump\n"),
1640 1655                      swap(dhp->dump_wordsize), isa);
1641 1656          }
1642 1657  }
1643 1658  
1644 1659  static void
1645 1660  usage(void)
1646 1661  {
1647 1662          (void) fprintf(stderr, gettext(
1648      -            "usage: file [-dh] [-M mfile] [-m mfile] [-f ffile] file ...\n"
1649      -            "       file [-dh] [-M mfile] [-m mfile] -f ffile\n"
     1663 +            "usage: file [-dhs] [-M mfile] [-m mfile] [-f ffile] file ...\n"
     1664 +            "       file [-dhs] [-M mfile] [-m mfile] -f ffile\n"
1650 1665              "       file -i [-h] [-f ffile] file ...\n"
1651 1666              "       file -i [-h] -f ffile\n"
1652 1667              "       file -c [-d] [-M mfile] [-m mfile]\n"));
1653 1668          exit(2);
1654 1669  }
1655 1670  
1656 1671  static uint32_t
1657 1672  swap_uint32(uint32_t in)
1658 1673  {
1659 1674          uint32_t out;
↓ open down ↓ 149 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX