[MacPorts] #64021: clamav @0.104.1_1 does not build on PPC Mac OS X 10.4.11, Tiger, because: 'O_SYMLINK' undeclared

MacPorts noreply at macports.org
Sat Jan 22 21:45:08 UTC 2022


#64021: clamav @0.104.1_1 does not build on PPC Mac OS X 10.4.11, Tiger, because:
'O_SYMLINK' undeclared
-----------------------------+--------------------
  Reporter:  ballapete       |      Owner:  (none)
      Type:  defect          |     Status:  new
  Priority:  Normal          |  Milestone:
 Component:  ports           |    Version:  2.7.1
Resolution:                  |   Keywords:  tiger
      Port:  legacy-support  |
-----------------------------+--------------------

Comment (by ballapete):

 The actual call in `clamav-0.104.2/libclamav/others_common.c` is:

 {{{
 fd = open(file_name, O_RDONLY | O_SYMLINK);
 }}}

 When `O_SYMLINK` is not defined and a file name is given, would it work to
 first check if the file is a symlink or a regular file and if yes open it
 read-only? The original code is:

 {{{
  1460   cl_error_t cli_realpath(const char *file_name, char
 **real_filename)
  1461   {
  1462       char *real_file_path = NULL;
  1463       cl_error_t status    = CL_EARG;
  1464   #ifdef _WIN32
  1465       HANDLE hFile = INVALID_HANDLE_VALUE;
  1466   #elif C_DARWIN
  1467       int fd = -1;
  1468   #endif
  1469
  1470       cli_dbgmsg("Checking realpath of %s\n", file_name);
  1471
  1472       if (NULL == file_name || NULL == real_filename) {
  1473           cli_warnmsg("cli_realpath: Invalid arguments.\n");
  1474           goto done;
  1475       }
  1476
  1477   #ifdef _WIN32
  1478
  1479       hFile = CreateFileA(file_name,                  // file to
 open
  1480                           GENERIC_READ,               // open for
 reading
  1481                           FILE_SHARE_READ,            // share for
 reading
  1482                           NULL,                       // default
 security
  1483                           OPEN_EXISTING,              // existing
 file only
  1484                           FILE_FLAG_BACKUP_SEMANTICS, // may be a
 directory
  1485                           NULL);                      // no attr.
 template
  1486       if (hFile == INVALID_HANDLE_VALUE) {
  1487           cli_warnmsg("Can't open file %s: %d\n", file_name,
 GetLastError());
  1488           status = CL_EOPEN;
  1489           goto done;
  1490       }
  1491
  1492       status = cli_get_filepath_from_handle(hFile, &real_file_path);
  1493
  1494   #elif C_DARWIN
  1495
  1496       /* Using the filepath from filedesc method on macOS because
  1497          realpath will fail to check the realpath of a symbolic link
 if
  1498          the link doesn't point to anything.
  1499          Plus, we probably don't wan tot follow the link in this
 case anyways,
  1500          so this will check the realpath of the link, and not of the
 thing the
  1501          link points to. */
  1502       fd = open(file_name, O_RDONLY | O_SYMLINK);
  1503       if (fd == -1) {
  1504           char err[128];
  1505           cli_strerror(errno, err, sizeof(err));
  1506           if (errno == EACCES) {
  1507               status = CL_EACCES;
  1508           } else {
  1509               status = CL_EOPEN;
  1510           }
  1511           cli_dbgmsg("Can't open file %s: %s\n", file_name, err);
  1512           goto done;
  1513       }
  1514
  1515       status = cli_get_filepath_from_filedesc(fd, &real_file_path);
  1516
  1517   #else
  1518
  1519       real_file_path = realpath(file_name, NULL);
  1520       if (NULL == real_file_path) {
  1521           status = CL_EMEM;
  1522           goto done;
  1523       }
  1524
  1525       status = CL_SUCCESS;
  1526
  1527   #endif
  1528
  1529       *real_filename = real_file_path;
  1530
  1531   done:
  1532
  1533   #ifdef _WIN32
  1534       if (hFile != INVALID_HANDLE_VALUE) {
  1535           CloseHandle(hFile);
  1536       }
  1537   #elif C_DARWIN
  1538       if (fd != -1) {
  1539           close(fd);
  1540       }
  1541   #endif
  1542
  1543       return status;
  1544   }
 }}}

 which could be turned into:

 {{{
 #if (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1050)
           if(S_ISLNK(file_name) | S_ISREG(file_name)) {
             fd = open(file_name, O_RDONLY);
           }
 #else
  1502       fd = open(file_name, O_RDONLY | O_SYMLINK);
 #endif  /* Tiger workaround for missing O_SYMLINK macro */
 }}}

 Could it? And would this work? (I am not really a C programmer.)

-- 
Ticket URL: <https://trac.macports.org/ticket/64021#comment:10>
MacPorts <https://www.macports.org/>
Ports system for macOS


More information about the macports-tickets mailing list