Skip to content

Check _DARWIN_FEATURE_ONLY_64_BIT_INODE to avoid errors from stat64 being undefined

Chris Burr requested to merge cburr/gfal2:fix-osx-arm64 into 2.20.x

Apple silicon macs no longer define stat64 as stat is already defined to be 64-bit. There is probably a nicer way to fix this but I struggled to find one. I'm happy to try out other ideas if people have any suggestions.

From man stat64:

TRANSITIONAL DESCRIPTION (NOW DEPRECATED)
     The fstat64, lstat64 and stat64 routines are equivalent to their corresponding non-64-suffixed routine, when 64-bit inodes are in effect.  They were added before there was support for the sym-
     bol variants, and so are now deprecated.  Instead of using these, set the _DARWIN_USE_64_BIT_INODE macro before including header files to force 64-bit inode support.

     The stat64 structure used by these deprecated routines is the same as the stat structure when 64-bit inodes are in effect (see above).

The actual error messages these changes fix are:

/Users/christopherburr/mambaforge/conda-bld/gfal2_1643033984631/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_plac/include/glib-2.0/glib/gmacros.h:1112:44: note: expanded from macro 'G_DEPRECATED_FOR'
#define G_DEPRECATED_FOR(f) __attribute__((__deprecated__("Use '" #f "' instead")))
                                           ^
/Users/christopherburr/mambaforge/conda-bld/gfal2_1643033984631/work/src/plugins/srm/gfal_srm_internal_ls.c:89:64: error: invalid application of 'sizeof' to an incomplete type 'struct stat64'
                             && buf && (sizeof(struct stat) == sizeof(struct stat64)),
                                                               ^     ~~~~~~~~~~~~~~~
/Users/christopherburr/mambaforge/conda-bld/gfal2_1643033984631/work/src/core/common/gfal_error.h:72:59: note: expanded from macro 'g_return_val_err_if_fail'
#define g_return_val_err_if_fail(exp, val, err, msg) if(!(exp)){ g_set_error(err, gfal2_get_core_quark(), EINVAL, msg); return val; }
                                                          ^~~
/Users/christopherburr/mambaforge/conda-bld/gfal2_1643033984631/work/src/plugins/srm/gfal_srm_internal_ls.c:89:78: note: forward declaration of 'struct stat64'
                             && buf && (sizeof(struct stat) == sizeof(struct stat64)),
                                                                             ^
1 warning and 1 error generated.
/Users/christopherburr/mambaforge/conda-bld/gfal2_1643033984631/work/src/plugins/srm/gfal_srm_readdir.c:38:50: warning: declaration of 'struct stat64' will not be visible outside of this function [-Wvisibility]
static void gfal_srm_stat64_to_stat(const struct stat64 *st64, struct stat *st)
                                                 ^
/Users/christopherburr/mambaforge/conda-bld/gfal2_1643033984631/work/src/plugins/srm/gfal_srm_readdir.c:40:9: error: invalid application of 'sizeof' to an incomplete type 'struct stat64'
    if (sizeof(struct stat64) == sizeof(struct stat))
        ^     ~~~~~~~~~~~~~~~
/Users/christopherburr/mambaforge/conda-bld/gfal2_1643033984631/work/src/plugins/srm/gfal_srm_readdir.c:38:50: note: forward declaration of 'struct stat64'
static void gfal_srm_stat64_to_stat(const struct stat64 *st64, struct stat *st)
                                                 ^
/Users/christopherburr/mambaforge/conda-bld/gfal2_1643033984631/work/src/plugins/srm/gfal_srm_readdir.c:43:34: error: incomplete definition of type 'struct stat64'
        st->st_dev = (dev_t) st64->st_dev;
                             ~~~~^
/Users/christopherburr/mambaforge/conda-bld/gfal2_1643033984631/work/src/plugins/srm/gfal_srm_readdir.c:38:50: note: forward declaration of 'struct stat64'
static void gfal_srm_stat64_to_stat(const struct stat64 *st64, struct stat *st)
Edited by Chris Burr

Merge request reports