From 1b1155305601f2198383188a621255c6837fab9d Mon Sep 17 00:00:00 2001 From: Thomas Klausner Date: Tue, 19 Jul 2022 11:37:00 +0200 Subject: [PATCH 1/4] cmake: Fix statvfs support --- build/cmake/setup.cmake | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/build/cmake/setup.cmake b/build/cmake/setup.cmake index cfe2cd17c9..bd2bc655e1 100644 --- a/build/cmake/setup.cmake +++ b/build/cmake/setup.cmake @@ -290,7 +290,7 @@ if(UNIX) wx_check_funcs(mkstemp mktemp) # get the library function to use for wxGetDiskSpace(): it is statfs() under - # Linux and *BSD and statvfs() under Solaris + # Linux and *BSD and statvfs() under Solaris and NetBSD wx_check_c_source_compiles(" return 0; } #if defined(__BSD__) @@ -308,6 +308,18 @@ if(UNIX) l += fs.f_blocks; l += fs.f_bavail;" HAVE_STATFS) + wx_check_c_source_compiles(" + return 0; } + #include + + int foo() { + long l; + struct statvfs fs; + statvfs(\"/\", &fs); + l = fs.f_bsize; + l += fs.f_blocks; + l += fs.f_bavail;" + HAVE_STATVFS) if(HAVE_STATFS) set(WX_STATFS_T "struct statfs") wx_check_cxx_source_compiles(" @@ -324,9 +336,8 @@ if(UNIX) statfs(\"/\", &fs);" HAVE_STATFS_DECL) else() - # TODO: implement statvfs checks if(HAVE_STATVFS) - set(WX_STATFS_T statvfs_t) + set(WX_STATFS_T "struct statvfs") endif() endif() From 684c149f49875c91e543163e62c9e1c54425f4a4 Mon Sep 17 00:00:00 2001 From: Thomas Klausner Date: Tue, 19 Jul 2022 12:07:22 +0200 Subject: [PATCH 2/4] Try improving consistency in statfs/statvfs usage. --- src/unix/utilsunx.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/unix/utilsunx.cpp b/src/unix/utilsunx.cpp index ac5181e187..ba11be166e 100644 --- a/src/unix/utilsunx.cpp +++ b/src/unix/utilsunx.cpp @@ -99,13 +99,11 @@ // some systems lack statfs() prototype in the system headers (AIX 4) extern "C" int statfs(const char *path, struct statfs *buf); #endif -#endif // HAVE_STATFS - -#ifdef HAVE_STATVFS +#elif defined(HAVE_STATVFS) #include #define wxStatfs statvfs -#endif // HAVE_STATVFS +#endif // HAVE_STATFS/HAVE_STATVFS #if defined(HAVE_STATFS) || defined(HAVE_STATVFS) // WX_STATFS_T is detected by configure @@ -1344,11 +1342,11 @@ bool wxGetDiskSpace(const wxString& path, wxDiskspaceSize_t *pTotal, wxDiskspace // under Solaris we also have to use f_frsize field instead of f_bsize // which is in general a multiple of f_frsize -#ifdef HAVE_STATVFS - wxDiskspaceSize_t blockSize = fs.f_frsize; -#else // HAVE_STATFS +#ifdef HAVE_STATFS wxDiskspaceSize_t blockSize = fs.f_bsize; -#endif // HAVE_STATVFS/HAVE_STATFS +#else // HAVE_STATVFS + wxDiskspaceSize_t blockSize = fs.f_frsize; +#endif // HAVE_STATFS/HAVE_STATVFS if ( pTotal ) { From d3563e4e5547ce97fbce8c37156cf41f4315193d Mon Sep 17 00:00:00 2001 From: Thomas Klausner Date: Wed, 20 Jul 2022 00:46:04 +0200 Subject: [PATCH 3/4] cmake: prefer statvfs (to statfs) Requested by VZ --- build/cmake/setup.cmake | 14 ++++++-------- src/unix/utilsunx.cpp | 22 +++++++++++----------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/build/cmake/setup.cmake b/build/cmake/setup.cmake index bd2bc655e1..2ec195fd5e 100644 --- a/build/cmake/setup.cmake +++ b/build/cmake/setup.cmake @@ -320,9 +320,11 @@ if(UNIX) l += fs.f_blocks; l += fs.f_bavail;" HAVE_STATVFS) - if(HAVE_STATFS) - set(WX_STATFS_T "struct statfs") - wx_check_cxx_source_compiles(" + if(HAVE_STATVFS) + set(WX_STATFS_T "struct statvfs") + elseif(HAVE_STATFS) + set(WX_STATFS_T "struct statfs") + wx_check_cxx_source_compiles(" return 0; } #if defined(__BSD__) #include @@ -334,11 +336,7 @@ if(UNIX) int foo() { struct statfs fs; statfs(\"/\", &fs);" - HAVE_STATFS_DECL) - else() - if(HAVE_STATVFS) - set(WX_STATFS_T "struct statvfs") - endif() + HAVE_STATFS_DECL) endif() if(NOT HAVE_STATFS AND NOT HAVE_STATVFS) diff --git a/src/unix/utilsunx.cpp b/src/unix/utilsunx.cpp index ba11be166e..0da4f598d8 100644 --- a/src/unix/utilsunx.cpp +++ b/src/unix/utilsunx.cpp @@ -85,7 +85,11 @@ // different platforms and even different versions of the same system (Solaris // 7 and 8): if you want to test for this, don't forget that the problems only // appear if the large files support is enabled -#ifdef HAVE_STATFS +#if defined(HAVE_STATVFS) + #include + + #define wxStatfs statvfs +#elif defined(HAVE_STATFS) #ifdef __BSD__ #include #include @@ -99,13 +103,9 @@ // some systems lack statfs() prototype in the system headers (AIX 4) extern "C" int statfs(const char *path, struct statfs *buf); #endif -#elif defined(HAVE_STATVFS) - #include +#endif // HAVE_STATVFS/HAVE_STATFS - #define wxStatfs statvfs -#endif // HAVE_STATFS/HAVE_STATVFS - -#if defined(HAVE_STATFS) || defined(HAVE_STATVFS) +#if defined(HAVE_STATVFS) || defined(HAVE_STATFS) // WX_STATFS_T is detected by configure #define wxStatfs_t WX_STATFS_T #endif @@ -1342,11 +1342,11 @@ bool wxGetDiskSpace(const wxString& path, wxDiskspaceSize_t *pTotal, wxDiskspace // under Solaris we also have to use f_frsize field instead of f_bsize // which is in general a multiple of f_frsize -#ifdef HAVE_STATFS - wxDiskspaceSize_t blockSize = fs.f_bsize; -#else // HAVE_STATVFS +#ifdef HAVE_STATVFS wxDiskspaceSize_t blockSize = fs.f_frsize; -#endif // HAVE_STATFS/HAVE_STATVFS +#else // HAVE_STATFS + wxDiskspaceSize_t blockSize = fs.f_bsize; +#endif // HAVE_STATVFS/HAVE_STATFS if ( pTotal ) { From e62e7a6d622422bf5522138f1e935fcc4c267622 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 24 Jul 2022 16:36:21 +0200 Subject: [PATCH 4/4] Check for statvfs() first in configure This POSIX function should be preferred to Linux/BSD-specific statfs() if it's available (as should always be the case nowadays). This commit is best viewed with Git --color-moved --color-moved-ws=ignore-all-space -w options. --- configure | 260 ++++++++++++++++++++++++++------------------------- configure.in | 173 +++++++++++++++++----------------- 2 files changed, 219 insertions(+), 214 deletions(-) diff --git a/configure b/configure index 5b4eea8051..e98d9f2b5c 100755 --- a/configure +++ b/configure @@ -35199,109 +35199,7 @@ fi done -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for statfs" >&5 -$as_echo_n "checking for statfs... " >&6; } -if ${wx_cv_func_statfs+:} false; then : - $as_echo_n "(cached) " >&6 -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - - #if defined(__BSD__) - #include - #include - #else - #include - #endif - -int -main () -{ - - long l; - struct statfs fs; - statfs("/", &fs); - l = fs.f_bsize; - l += fs.f_blocks; - l += fs.f_bavail; - - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - wx_cv_func_statfs=yes -else - wx_cv_func_statfs=no - -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $wx_cv_func_statfs" >&5 -$as_echo "$wx_cv_func_statfs" >&6; } - -if test "$wx_cv_func_statfs" = "yes"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for statfs declaration" >&5 -$as_echo_n "checking for statfs declaration... " >&6; } -if ${wx_cv_func_statfs_decl+:} false; then : - $as_echo_n "(cached) " >&6 -else - ac_ext=cpp -ac_cpp='$CXXCPP $CPPFLAGS' -ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_cxx_compiler_gnu - - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - - #if defined(__BSD__) - #include - #include - #else - #include - #endif - -int -main () -{ - - struct statfs fs; - statfs("", &fs); - - ; - return 0; -} -_ACEOF -if ac_fn_cxx_try_compile "$LINENO"; then : - wx_cv_func_statfs_decl=yes -else - wx_cv_func_statfs_decl=no - -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu - - -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $wx_cv_func_statfs_decl" >&5 -$as_echo "$wx_cv_func_statfs_decl" >&6; } - - if test "$wx_cv_func_statfs_decl" = "yes"; then - $as_echo "#define HAVE_STATFS_DECL 1" >>confdefs.h - - fi - - wx_cv_type_statvfs_t="struct statfs" - $as_echo "#define HAVE_STATFS 1" >>confdefs.h - -else - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for statvfs" >&5 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for statvfs" >&5 $as_echo_n "checking for statvfs... " >&6; } if ${wx_cv_func_statvfs+:} false; then : $as_echo_n "(cached) " >&6 @@ -35309,14 +35207,14 @@ else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ - #include - #include + #include + #include int main () { - statvfs("/", NULL); + statvfs("/", NULL); ; return 0; @@ -35334,8 +35232,8 @@ fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $wx_cv_func_statvfs" >&5 $as_echo "$wx_cv_func_statvfs" >&6; } - if test "$wx_cv_func_statvfs" = "yes"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for statvfs argument type" >&5 +if test "$wx_cv_func_statvfs" = "yes"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for statvfs argument type" >&5 $as_echo_n "checking for statvfs argument type... " >&6; } if ${wx_cv_type_statvfs_t+:} false; then : $as_echo_n "(cached) " >&6 @@ -35346,21 +35244,21 @@ ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_cxx_compiler_gnu - cat confdefs.h - <<_ACEOF >conftest.$ac_ext + cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ - #include + #include int main () { - long l; - statvfs_t fs; - statvfs("/", &fs); - l = fs.f_bsize; - l += fs.f_blocks; - l += fs.f_bavail; + long l; + statvfs_t fs; + statvfs("/", &fs); + l = fs.f_bsize; + l += fs.f_blocks; + l += fs.f_bavail; ; return 0; @@ -35370,21 +35268,21 @@ if ac_fn_cxx_try_compile "$LINENO"; then : wx_cv_type_statvfs_t=statvfs_t else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext + cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ - #include + #include int main () { - long l; - struct statvfs fs; - statvfs("/", &fs); - l = fs.f_bsize; - l += fs.f_blocks; - l += fs.f_bavail; + long l; + struct statvfs fs; + statvfs("/", &fs); + l = fs.f_bsize; + l += fs.f_blocks; + l += fs.f_bavail; ; return 0; @@ -35401,7 +35299,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - ac_ext=c + ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' @@ -35412,12 +35310,116 @@ fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $wx_cv_type_statvfs_t" >&5 $as_echo "$wx_cv_type_statvfs_t" >&6; } - if test "$wx_cv_type_statvfs_t" != "unknown"; then - $as_echo "#define HAVE_STATVFS 1" >>confdefs.h + if test "$wx_cv_type_statvfs_t" != "unknown"; then + $as_echo "#define HAVE_STATVFS 1" >>confdefs.h + + fi +else + wx_cv_type_statvfs_t="unknown" +fi + +if test "$wx_cv_type_statvfs_t" = "unknown"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for statfs" >&5 +$as_echo_n "checking for statfs... " >&6; } +if ${wx_cv_func_statfs+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + #if defined(__BSD__) + #include + #include + #else + #include + #endif + +int +main () +{ + + long l; + struct statfs fs; + statfs("/", &fs); + l = fs.f_bsize; + l += fs.f_blocks; + l += fs.f_bavail; + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + wx_cv_func_statfs=yes +else + wx_cv_func_statfs=no + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $wx_cv_func_statfs" >&5 +$as_echo "$wx_cv_func_statfs" >&6; } + + if test "$wx_cv_func_statfs" = "yes"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for statfs declaration" >&5 +$as_echo_n "checking for statfs declaration... " >&6; } +if ${wx_cv_func_statfs_decl+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_ext=cpp +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + #if defined(__BSD__) + #include + #include + #else + #include + #endif + +int +main () +{ + + struct statfs fs; + statfs("", &fs); + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + wx_cv_func_statfs_decl=yes +else + wx_cv_func_statfs_decl=no + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $wx_cv_func_statfs_decl" >&5 +$as_echo "$wx_cv_func_statfs_decl" >&6; } + + if test "$wx_cv_func_statfs_decl" = "yes"; then + $as_echo "#define HAVE_STATFS_DECL 1" >>confdefs.h fi - else - wx_cv_type_statvfs_t="unknown" + + wx_cv_type_statvfs_t="struct statfs" + $as_echo "#define HAVE_STATFS 1" >>confdefs.h + fi fi diff --git a/configure.in b/configure.in index 15f0b38b7b..a0732fc5c0 100644 --- a/configure.in +++ b/configure.in @@ -4532,35 +4532,77 @@ fi dnl check for the function for temp files creation AC_CHECK_FUNCS(mkstemp mktemp, break) -dnl get the library function to use for wxGetDiskSpace(): it is statfs() under -dnl Linux and *BSD and statvfs() under Solaris -AC_CACHE_CHECK(for statfs, wx_cv_func_statfs, +dnl get the library function to use for wxGetDiskSpace(): prefer POSIX +dnl statvfs() if it exists, but fall back to Linux/BSD-specific statfs() if +dnl necessary. +AC_CACHE_CHECK(for statvfs, wx_cv_func_statvfs, AC_TRY_COMPILE( [ - #if defined(__BSD__) - #include - #include - #else - #include - #endif + #include + #include ], [ - long l; - struct statfs fs; - statfs("/", &fs); - l = fs.f_bsize; - l += fs.f_blocks; - l += fs.f_bavail; + statvfs("/", NULL); ], - wx_cv_func_statfs=yes, - wx_cv_func_statfs=no + wx_cv_func_statvfs=yes, + wx_cv_func_statvfs=no ) ) -if test "$wx_cv_func_statfs" = "yes"; then - dnl check whether we have its dcelaration too: some systems (AIX 4) lack it - AC_CACHE_CHECK(for statfs declaration, wx_cv_func_statfs_decl, +if test "$wx_cv_func_statvfs" = "yes"; then + dnl we also have to check whether we should use statvfs_t (works under + dnl Solaris 8, doesn't work under Solaris 7) or "struct statvfs" (vice + dnl versa) as the argument for statvfs in 64 bit off_t mode (in 32 bit + dnl mode both work fine) + dnl + dnl for this check C++ compiler has to be used as passing incompatible + dnl pointers is just a warning and not an error in C + AC_CACHE_CHECK(for statvfs argument type, wx_cv_type_statvfs_t, AC_LANG_PUSH(C++) + AC_TRY_COMPILE( + [ + #include + ], + [ + long l; + statvfs_t fs; + statvfs("/", &fs); + l = fs.f_bsize; + l += fs.f_blocks; + l += fs.f_bavail; + ], + wx_cv_type_statvfs_t=statvfs_t, + [ + AC_TRY_COMPILE( + [ + #include + ], + [ + long l; + struct statvfs fs; + statvfs("/", &fs); + l = fs.f_bsize; + l += fs.f_blocks; + l += fs.f_bavail; + ], + wx_cv_type_statvfs_t="struct statvfs", + wx_cv_type_statvfs_t="unknown" + ) + ] + ) + AC_LANG_POP() + ) + + if test "$wx_cv_type_statvfs_t" != "unknown"; then + AC_DEFINE(HAVE_STATVFS) + fi +else + dnl set it for the test below + wx_cv_type_statvfs_t="unknown" +fi + +if test "$wx_cv_type_statvfs_t" = "unknown"; then + AC_CACHE_CHECK(for statfs, wx_cv_func_statfs, AC_TRY_COMPILE( [ #if defined(__BSD__) @@ -4571,86 +4613,47 @@ if test "$wx_cv_func_statfs" = "yes"; then #endif ], [ - struct statfs fs; - statfs("", &fs); + long l; + struct statfs fs; + statfs("/", &fs); + l = fs.f_bsize; + l += fs.f_blocks; + l += fs.f_bavail; ], - wx_cv_func_statfs_decl=yes, - wx_cv_func_statfs_decl=no - ) - AC_LANG_POP() - ) - - if test "$wx_cv_func_statfs_decl" = "yes"; then - AC_DEFINE(HAVE_STATFS_DECL) - fi - - wx_cv_type_statvfs_t="struct statfs" - AC_DEFINE(HAVE_STATFS) -else - AC_CACHE_CHECK(for statvfs, wx_cv_func_statvfs, - AC_TRY_COMPILE( - [ - #include - #include - ], - [ - statvfs("/", NULL); - ], - wx_cv_func_statvfs=yes, - wx_cv_func_statvfs=no + wx_cv_func_statfs=yes, + wx_cv_func_statfs=no ) ) - if test "$wx_cv_func_statvfs" = "yes"; then - dnl we also have to check whether we should use statvfs_t (works under - dnl Solaris 8, doesn't work under Solaris 7) or "struct statvfs" (vice - dnl versa) as the argument for statvfs in 64 bit off_t mode (in 32 bit - dnl mode both work fine) - dnl - dnl for this check C++ compiler has to be used as passing incompatible - dnl pointers is just a warning and not an error in C - AC_CACHE_CHECK(for statvfs argument type, wx_cv_type_statvfs_t, + if test "$wx_cv_func_statfs" = "yes"; then + dnl check whether we have its dcelaration too: some systems (AIX 4) lack it + AC_CACHE_CHECK(for statfs declaration, wx_cv_func_statfs_decl, AC_LANG_PUSH(C++) AC_TRY_COMPILE( [ - #include + #if defined(__BSD__) + #include + #include + #else + #include + #endif ], [ - long l; - statvfs_t fs; - statvfs("/", &fs); - l = fs.f_bsize; - l += fs.f_blocks; - l += fs.f_bavail; + struct statfs fs; + statfs("", &fs); ], - wx_cv_type_statvfs_t=statvfs_t, - [ - AC_TRY_COMPILE( - [ - #include - ], - [ - long l; - struct statvfs fs; - statvfs("/", &fs); - l = fs.f_bsize; - l += fs.f_blocks; - l += fs.f_bavail; - ], - wx_cv_type_statvfs_t="struct statvfs", - wx_cv_type_statvfs_t="unknown" - ) - ] + wx_cv_func_statfs_decl=yes, + wx_cv_func_statfs_decl=no ) AC_LANG_POP() ) - if test "$wx_cv_type_statvfs_t" != "unknown"; then - AC_DEFINE(HAVE_STATVFS) + if test "$wx_cv_func_statfs_decl" = "yes"; then + AC_DEFINE(HAVE_STATFS_DECL) fi - else - dnl set it for the test below - wx_cv_type_statvfs_t="unknown" + + wx_cv_type_statvfs_t="struct statfs" + AC_DEFINE(HAVE_STATFS) fi fi