Opened 7 years ago

Closed 7 years ago

Last modified 6 years ago

#5780 closed defect (fixed)

MacOS X deprecated stat64

Reported by: Kurt Schwehr Owned by: Kurt Schwehr
Priority: normal Milestone: 2.0.0
Component: default Version: unspecified
Severity: normal Keywords:
Cc:

Description

Related to stricter no compiler warnings: #5414

Maybe it would be better to check more carefully, but apple does roughly this on 10.9:

#if !__DARWIN_ONLY_64_BIT_INO_T
int     stat64(const char *, struct stat64 *) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5,__MAC_10_6,__IPHONE_NA,__IPHONE_NA);
#endif

Giving:

g++ -Wextra -Werror -g -O2 -DHAVE_SSE_AT_COMPILE_TIME -Wall -Wextra -Werror -DOGR_ENABLED -I/sw/include -I/Users/schwehr/src/gdal/gdal-1.11-svn/port -I/sw -I/sw/include -I/sw/include -I/sw -I/sw/include -I/sw -I/sw/include -I/sw/include -I/sw -I/sw/include -I/sw -I/sw/include -I/sw -I/sw/include -I/sw/include -DHAVE_CURL -DHAVE_LIBZ -I/sw/include/libxml2 -I/sw/include -DHAVE_LIBXML2 -c cpl_vsil_unix_stdio_64.cpp  -fno-common -DPIC -o .libs/cpl_vsil_unix_stdio_64.o
cpl_vsil_unix_stdio_64.cpp:514:13: error: 'stat64' is deprecated: first deprecated in OS X 10.6
      [-Werror,-Wdeprecated-declarations]
    return( VSI_STAT64( pszFilename, pStatBuf ) );
            ^
/Users/schwehr/src/gdal/gdal-1.11-svn/port/cpl_config.h:206:20: note: expanded from macro 'VSI_STAT64'
#define VSI_STAT64 stat64
                   ^
/usr/include/sys/stat.h:380:5: note: 'stat64' has been explicitly marked deprecated here
int     stat64(const char *, struct stat64 *) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5,__MAC_...
        ^
1 error generated.

A possible solution that should work for Mac OSX >= 10.6.

  • m4/acinclude.m4

     
    192192  if test x"$with_unix_stdio_64" = x"yes" ; then
    193193    AC_MSG_RESULT([yes])
    194194
    195     AC_CHECK_FUNC(stat64, VSI_STAT64=stat64 VSI_STAT64_T=stat64, VSI_STAT64=stat VSI_STAT64_T=stat)
     195    case "${host_os}" in
     196      darwin*)
     197        VSI_STAT64=stat
     198        VSI_STAT64_T=stat
     199        ;;
     200      *)     
     201        AC_CHECK_FUNC(stat64, VSI_STAT64=stat64 VSI_STAT64_T=stat64, VSI_STAT64=stat VSI_STAT64_T=stat)
     202        ;;
     203    esac
    196204    AC_CHECK_FUNC(fopen64, VSI_FOPEN64=fopen64, VSI_FOPEN64=fopen)
    197205    AC_CHECK_FUNC(ftruncate64, VSI_FTRUNCATE64=ftruncate64, VSI_FTRUNCATE64=ftruncate)

Thoughts?

Change History (8)

comment:1 Changed 7 years ago by Even Rouault

Are you sure that regular stat on MacOsX is going to return 64bit st_size ? What about older Mac OSX, and 32bit variants (if that actually exist) ?

comment:2 Changed 7 years ago by Kurt Schwehr

Here is a quick exploration of the results. TL;DR - stat.st_size is always 8 bytes

I did not check struct stat64.

#include <iostream>
#include <sys/stat.h>
using namespace std;

int main(void) {
  cout << "sizeof (void*): " << sizeof(void *) << "\n";
  cout << "sizeof int: " << sizeof(int) << "\n";
  cout << "sizeof long: " << sizeof(long) << "\n";

  cout << "\n";
#ifdef _DARWIN_FEATURE_64_BIT_INODE
  cout << "_DARWIN_FEATURE_64_BIT_INODE -- defined\n";
#else
  cout << "_DARWIN_FEATURE_64_BIT_INODE -- not defined\n";
#endif

  struct stat s;
  cout << "sizeof st_size: " << sizeof(s.st_size) << "\n";
  cout << "sizeof st_ino: " << sizeof(s.st_ino) << "\n";
  cout << "sizeof st_blocks: " << sizeof(s.st_blocks) << "\n";
  cout << "sizeof st_dev: " << sizeof(s.st_dev) << "\n";
  cout << "sizeof st_rdev: " << sizeof(s.st_rdev) << "\n";

  cout << "\n";
  cout << "sizeof dev_t: " << sizeof(dev_t) << "\n";
  cout << "sizeof ino_t: " << sizeof(ino_t) << "\n";
  cout << "sizeof mode_t: " << sizeof(mode_t) << "\n";
  cout << "sizeof nlink_t: " << sizeof(nlink_t) << "\n";
  cout << "sizeof uid_t: " << sizeof(uid_t) << "\n";
  cout << "sizeof gid_t: " << sizeof(gid_t) << "\n";
  cout << "sizeof struct timespec: " << sizeof(struct timespec) << "\n";
  cout << "sizeof off_t: " << sizeof(off_t) << "\n";
  cout << "sizeof quad_t: " << sizeof(quad_t) << "\n";
  cout << "sizeof u_long: " << sizeof(u_long) << "\n";

  return 0;
}

Mac OSX 10.9

64 bit is the default so -m64 is redundant

uname -s -r ; clang++ -m64 mac_test.cc -Wall -Wextra -o mac_test && ./mac_test
Darwin 13.4.0
sizeof (void*): 8
sizeof int: 4
sizeof long: 8

_DARWIN_FEATURE_64_BIT_INODE -- defined
sizeof st_size: 8
sizeof st_ino: 8
sizeof st_blocks: 8
sizeof st_dev: 4
sizeof st_rdev: 4

sizeof dev_t: 4
sizeof ino_t: 8
sizeof mode_t: 2
sizeof nlink_t: 2
sizeof uid_t: 4
sizeof gid_t: 4
sizeof struct timespec: 16
sizeof off_t: 8
sizeof quad_t: 8
sizeof u_long: 8
uname -s -r ; clang++ -m32 mac_test.cc -Wall -Wextra -o mac_test && ./mac_test
Darwin 13.4.0
sizeof (void*): 4
sizeof int: 4
sizeof long: 4

_DARWIN_FEATURE_64_BIT_INODE -- defined
sizeof st_size: 8
sizeof st_ino: 8
sizeof st_blocks: 8
sizeof st_dev: 4
sizeof st_rdev: 4

sizeof dev_t: 4
sizeof ino_t: 8
sizeof mode_t: 2
sizeof nlink_t: 2
sizeof uid_t: 4
sizeof gid_t: 4
sizeof struct timespec: 8
sizeof off_t: 8
sizeof quad_t: 8
sizeof u_long: 4

Old Mac OS X Server 10.5.8 machine from circa 2008 (x86)

uname -s -r; g++ -m64 mac_test.cc -Wall -Wextra -o mac_test && ./mac_test
Darwin 9.8.0
sizeof (void*): 8
sizeof int: 4
sizeof long: 8

_DARWIN_FEATURE_64_BIT_INODE -- not defined
sizeof st_size: 8
sizeof st_ino: 4
sizeof st_blocks: 8
sizeof st_dev: 4
sizeof st_rdev: 4

sizeof dev_t: 4
sizeof ino_t: 4
sizeof mode_t: 2
sizeof nlink_t: 2
sizeof uid_t: 4
sizeof gid_t: 4
sizeof struct timespec: 16
sizeof off_t: 8

And the default 32 bit build

uname -s -r; g++ -m32 mac_test.cc -Wall -Wextra -o mac_test && ./mac_test
Darwin 9.8.0
sizeof (void*): 4
sizeof int: 4
sizeof long: 4

_DARWIN_FEATURE_64_BIT_INODE -- not defined
sizeof st_size: 8
sizeof st_ino: 4
sizeof st_blocks: 8
sizeof st_dev: 4
sizeof st_rdev: 4

sizeof dev_t: 4
sizeof ino_t: 4
sizeof mode_t: 2
sizeof nlink_t: 2
sizeof uid_t: 4
sizeof gid_t: 4
sizeof struct timespec: 8
sizeof off_t: 8

comment:3 Changed 7 years ago by Kurt Schwehr

Any reason to hold off on submitting this to trunk? st_size is always 8 bytes, so it seems okay back to 10.5.

comment:4 Changed 7 years ago by Even Rouault

Go ahead if you feel confident about it.

comment:5 Changed 7 years ago by Kurt Schwehr

Owner: changed from warmerdam to Kurt Schwehr

It's in trunk as r28182. I'd like to put this in 1.11-svn. If that's okay, I think we should give it a few weeks in trunk first.

comment:6 Changed 7 years ago by Even Rouault

configure should probably be regenerated too (so that the Mac Travis instance can test this).

Personnaly I'm not really enthousiastic about seeing that land in 1.11 too. This is cleanup, not a bug fix. It might break stuff for people with older OS X versions.

comment:7 Changed 7 years ago by Even Rouault

Milestone: 2.0
Resolution: fixed
Status: newclosed

comment:8 Changed 6 years ago by Even Rouault

Milestone: 2.02.0.0

Milestone renamed

Note: See TracTickets for help on using tickets.