Print this page
10476 file(1) could be smatch clean
10366 ld(1) should support GNU-style linker sets
10581 ld(1) should know kernel modules are a thing

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/file/file.c
          +++ new/usr/src/cmd/file/file.c
↓ open down ↓ 11 lines elided ↑ open up ↑
  12   12   *
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
  22      -/*        All Rights Reserved   */
       22 +/*        All Rights Reserved   */
  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   * Copyright (c) 2018, Joyent, Inc.
  32   32   */
↓ open down ↓ 574 lines elided ↑ open up ↑
 607  607  /*
 608  608   * def_position_tests() - applies default position-sensitive tests,
 609  609   *      looking for values in specific positions in the file.
 610  610   *      These are followed by default (followed by possibly some
 611  611   *      non-default) magic file tests.
 612  612   *
 613  613   *      All position-sensitive tests, default or otherwise, must
 614  614   *      be applied before context-sensitive tests, to avoid
 615  615   *      false context-sensitive matches.
 616  616   *
 617      - *      Returns -1 on error which should result in error (non-zero)
      617 + *      Returns -1 on error which should result in error (non-zero)
 618  618   *      exit status for the file utility.
 619  619   *      Returns 0 if no matching file type found.
 620  620   *      Returns 1 if matching file type found.
 621  621   */
 622  622  
 623  623  static int
 624  624  def_position_tests(char *file)
 625  625  {
 626  626          if (sccs()) {   /* look for "1hddddd" where d is a digit */
 627  627                  (void) printf("sccs \n");
↓ open down ↓ 218 lines elided ↑ open up ↑
 846  846          IS_ascii = 1;
 847  847          if (fbsz < FBSZ)
 848  848                  Max = fbsz;
 849  849          else
 850  850                  Max = FBSZ - MB_LEN_MAX; /* prevent cut of wchar read */
 851  851          /* end modification for multibyte env */
 852  852  
 853  853          for (i = 0; i < Max; /* null */)
 854  854                  if (fbuf[i] & 0200) {
 855  855                          IS_ascii = 0;
 856      -                        if (fbuf[0] == '\100' && fbuf[1] == '\357') {
      856 +                        if ((fbuf[0] == '\100') &&
      857 +                            ((uchar_t)fbuf[1] == (uchar_t)'\357')) {
 857  858                                  (void) printf(gettext("troff output\n"));
 858  859                                  return;
 859  860                          }
 860  861                  /* start modification for multibyte env */
 861  862                          if ((length = mbtowc(&wchar, &fbuf[i], MB_CUR_MAX))
 862  863                              <= 0 || !iswprint(wchar)) {
 863  864                                  (void) printf(gettext("data\n"));
 864  865                                  return;
 865  866                          }
 866  867                          i += length;
↓ open down ↓ 456 lines elided ↑ open up ↑
1323 1324                          (void) printf(" %s", gettext("core file"));
1324 1325          }
1325 1326  
1326 1327          /* Print machine info */
1327 1328          print_elf_machine(EInfo.machine);
1328 1329  
1329 1330          /* Print Version */
1330 1331          if (version == 1)
1331 1332                  (void) printf(" %s %d", gettext("Version"), version);
1332 1333  
     1334 +        if (EInfo.kmod) {
     1335 +                (void) printf(", %s", gettext("kernel module"));
     1336 +        }
     1337 +
1333 1338          /* Print Flags */
1334 1339          print_elf_flags(EInfo);
1335 1340  
1336 1341          /* Last bit, if it is a core */
1337 1342          if (EInfo.core_type != EC_NOTCORE) {
1338 1343                  /* Print the program name that dumped this core */
1339 1344                  (void) printf(gettext(", from '%s'"), EInfo.fname);
1340 1345                  return (0);
1341 1346          }
1342 1347  
↓ open down ↓ 133 lines elided ↑ open up ↑
1476 1481                  while (fbuf[i++] != '\n')
1477 1482                          if (i >= fbsz)
1478 1483                                  return (0);
1479 1484                  while (fbuf[i] == '\n')
1480 1485                          if (i++ >= fbsz)
1481 1486                                  return (0);
1482 1487          }
1483 1488          return (1);
1484 1489  }
1485 1490  
     1491 +/* look for "1hddddd" where d is a digit */
1486 1492  static int
1487 1493  sccs(void)
1488      -{                               /* look for "1hddddd" where d is a digit */
     1494 +{
1489 1495          register int j;
1490 1496  
1491 1497          if (fbuf[0] == 1 && fbuf[1] == 'h') {
1492 1498                  for (j = 2; j <= 6; j++) {
1493 1499                          if (isdigit(fbuf[j]))
1494 1500                                  continue;
1495 1501                          else
1496 1502                                  return (0);
1497 1503                  }
1498 1504          } else {
↓ open down ↓ 402 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX