Print this page
4732 /usr/bin/file should provide -b option  for compatiblity with GNU/BSD file
Reviewed by: Andy Stormont <andyjstormont@gmail.com>
Reviewed by: Serghei Samsi <sscdvp@gmail.com>
Reviewed by: Alexander Pyhalov <alp@rsu.ru>
Reviewed by: Garrett D'Amore <garrett@damore.org>

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/file/file.c
          +++ new/usr/src/cmd/file/file.c
↓ open down ↓ 197 lines elided ↑ open up ↑
 198  198   * within individual error messages.
 199  199   */
 200  200  const char *File = "file";
 201  201  
 202  202  int
 203  203  main(int argc, char **argv)
 204  204  {
 205  205          char    *p;
 206  206          int     ch;
 207  207          FILE    *fl;
      208 +        int     bflg = 0;
 208  209          int     cflg = 0;
 209  210          int     eflg = 0;
 210  211          int     fflg = 0;
 211  212          char    *ap = NULL;
 212  213          int     pathlen;
 213  214          char    **filep;
 214  215  
 215  216          (void) setlocale(LC_ALL, "");
 216  217  #if !defined(TEXT_DOMAIN)       /* Should be defined by cc -D */
 217  218  #define TEXT_DOMAIN "SYS_TEST"  /* Use this only if it weren't */
 218  219  #endif
 219  220          (void) textdomain(TEXT_DOMAIN);
 220  221  
 221      -        while ((ch = getopt(argc, argv, "M:cdf:him:")) != EOF) {
      222 +        while ((ch = getopt(argc, argv, "M:bcdf:him:")) != EOF) {
 222  223                  switch (ch) {
 223  224  
 224  225                  case 'M':
 225  226                          add_to_mlist(optarg, !dflg);
 226  227                          M_flg++;
 227  228                          break;
 228  229  
      230 +                case 'b':
      231 +                        bflg++;
      232 +                        break;
      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                          }
↓ open down ↓ 42 lines elided ↑ open up ↑
 281  286                  case '?':
 282  287                          eflg++;
 283  288                          break;
 284  289                  }
 285  290          }
 286  291          if (!cflg && !fflg && (eflg || optind == argc))
 287  292                  usage();
 288  293          if (iflg && (dflg || mflg || M_flg)) {
 289  294                  usage();
 290  295          }
 291      -        if (iflg && cflg) {
      296 +        if ((iflg && cflg) || (cflg && bflg)) {
 292  297                  usage();
 293  298          }
 294  299  
 295  300          if (!dflg && !mflg && !M_flg && !iflg) {
 296  301          /* no -d, -m, nor -M option; also -i option doesn't need magic  */
 297  302                  default_magic();
 298  303                  if (f_mkmtab(dfile, cflg, 0) == -1) {
 299  304                          exit(2);
 300  305                  }
 301  306          }
↓ open down ↓ 100 lines elided ↑ open up ↑
 402  407                          if ((p = fgets(ap, pathlen, fl)) == NULL) {
 403  408                                  fflg = 0;
 404  409                                  optind--;
 405  410                                  continue;
 406  411                          }
 407  412                          l = strlen(p);
 408  413                          if (l > 0)
 409  414                                  p[l - 1] = '\0';
 410  415                  } else
 411  416                          p = argv[optind];
 412      -                prf(p);                         /* print "file_name:<tab>" */
      417 +
      418 +                if (!bflg)
      419 +                        prf(p);         /* print "file_name:<tab>" */
 413  420  
 414  421                  if (type(p))
 415  422                          tret = 1;
 416  423          }
 417  424          if (ap != NULL)
 418  425                  free(ap);
 419  426          if (tret != 0)
 420  427                  exit(tret);
 421  428  
 422  429          if (ferror(stdout) != 0) {
↓ open down ↓ 1215 lines elided ↑ open up ↑
1638 1645          } else {
1639 1646                  (void) printf(gettext("SunOS %u-bit %s crash dump\n"),
1640 1647                      swap(dhp->dump_wordsize), isa);
1641 1648          }
1642 1649  }
1643 1650  
1644 1651  static void
1645 1652  usage(void)
1646 1653  {
1647 1654          (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"
1650      -            "       file -i [-h] [-f ffile] file ...\n"
1651      -            "       file -i [-h] -f ffile\n"
     1655 +            "usage: file [-bdh] [-M mfile] [-m mfile] [-f ffile] file ...\n"
     1656 +            "       file [-bdh] [-M mfile] [-m mfile] -f ffile\n"
     1657 +            "       file -i [-bh] [-f ffile] file ...\n"
     1658 +            "       file -i [-bh] -f ffile\n"
1652 1659              "       file -c [-d] [-M mfile] [-m mfile]\n"));
1653 1660          exit(2);
1654 1661  }
1655 1662  
1656 1663  static uint32_t
1657 1664  swap_uint32(uint32_t in)
1658 1665  {
1659 1666          uint32_t out;
1660 1667  
1661 1668          out = (in & 0x000000ff) << 24;
↓ open down ↓ 147 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX