diff mbox series

P*rtability of dash to legacy systems, such as AT&T Unix PC : 02-stat64

Message ID 936c6eb0-4044-4478-b052-ed1ca47af0b7@knaff.lu (mailing list archive)
State Under Review
Delegated to: Herbert Xu
Headers show
Series P*rtability of dash to legacy systems, such as AT&T Unix PC : 02-stat64 | expand

Commit Message

Alain Knaff Nov. 17, 2024, 9:31 a.m. UTC
Hi,

The second element of the patch set fixes the stat64 redefinition so
that it can compile on Solaris.

Indeed, rather than supplying stat64 etc. as a normal library
function, Solaris uses a #define, which means that AC_CHECK_FUNCTION
won't detect it, resulting in a compilation where struct stat and
struct stat64 conflict with each other.

This patch replaces the AC_CHECK_FUNCTION calls with AC_CHECK_DECL,
and adds includes where needed.

Checking for declarations rather than functions would miss a
hypothetical situation where a library function stat64 would exists
which lacks a prototype declaration. However, this is very unlikely to
happen in practice, because general availability of prototypes of
system function predates availability of 64 bit file offset by years.

This patch is not strictly needed for UnixPC compatibility, and may be
skipped if it causes problems elsewhere.

All this being said, while studying what happens on Solaris, I
wondered about three alternative solutions:
 1. the problem happens because the #define statements for stat64
    happen in config.h *before* inclusion of system includes such as
    sys/stat.h
    If the #define happened *after* inclusion of system includes, the
    problem would result in a mere warning when it happens. So why not
    move those defines to system.h?

 2. similarly, rather than defining stat64, why not make up a new name,
    such as statw, and #define statw to be stat or stat64 depending on
    what is available?

 3. and finally, is the whole shebang actually needed if we use
    AC_SYS_LARGEFILE? This autoconf directive adds an appropriate
    #define before inclusion of system files to instruct them to make
    the relevant system calls "64-bit clean". That way we wouldn't need
    to mess around with redefining stat64 our-self.

Regards,

Alain
diff mbox series

Patch

diff -X ../exclude.txt -urN dash-0.5.12+01-remove-extraneous/configure.ac dash-0.5.12+02-stat64/configure.ac
--- dash-0.5.12+01-remove-extraneous/configure.ac	2024-11-10 10:14:41.608305106 +0000
+++ dash-0.5.12+02-stat64/configure.ac	2024-11-10 16:04:42.792587032 +0000
@@ -140,28 +140,29 @@ 
 fi
 
 dnl Check for stat64 (dietlibc/klibc).
-AC_CHECK_DECL(stat64, AC_CHECK_FUNC(stat64))
-if test "$ac_cv_func_stat64" != yes; then
+AC_CHECK_DECL(stat64,, [
 	AC_DEFINE(fstat64, fstat, [64-bit operations are the same as 32-bit])
 	AC_DEFINE(lstat64, lstat, [64-bit operations are the same as 32-bit])
 	AC_DEFINE(stat64, stat, [64-bit operations are the same as 32-bit])
-fi
+])
 
-AC_CHECK_FUNC(glob64,, [
+AC_CHECK_DECL(glob64,, [
 	AC_DEFINE(glob64_t, glob_t, [64-bit operations are the same as 32-bit])
 	AC_DEFINE(glob64, glob, [64-bit operations are the same as 32-bit])
 	AC_DEFINE(globfree64, globfree,
 		  [64-bit operations are the same as 32-bit])
-])
+],[#ifdef HAVE_GLOB
+#include <glob.h>
+#endif])
 
 dnl OS X apparently has stat64 but not open64.
-AC_CHECK_FUNC(open64,, [
+AC_CHECK_DECL(open64,, [
 	AC_DEFINE(open64, open, [64-bit operations are the same as 32-bit])
 	AC_DEFINE(readdir64, readdir,
 		  [64-bit operations are the same as 32-bit])
 	AC_DEFINE(dirent64, dirent,
 		  [64-bit operations are the same as 32-bit])
-])
+],[#include <fcntl.h>])
 
 dnl Check if struct stat has st_mtim.
 AC_MSG_CHECKING(for stat::st_mtim)