aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2023-06-17 00:52:12 +1000
committerSteve Bennett <steveb@workware.net.au>2023-06-20 12:46:21 +1000
commit9e78cc8a97b7ecf6afbbe9a35305daf3459cead6 (patch)
tree64af616586f7ab30e7652fad72a846392220eede
parent5246daeb5d517ef4d68834537862e928961f6a41 (diff)
downloadjimtcl-9e78cc8a97b7ecf6afbbe9a35305daf3459cead6.zip
jimtcl-9e78cc8a97b7ecf6afbbe9a35305daf3459cead6.tar.gz
jimtcl-9e78cc8a97b7ecf6afbbe9a35305daf3459cead6.tar.bz2
file: use 64 bit stat functions if necessary
Some 32 bit systems may require explicit use of stat64, etc. Fixes #263
-rw-r--r--auto.def10
-rw-r--r--jim-file.c6
-rw-r--r--jimiocompat.h22
3 files changed, 31 insertions, 7 deletions
diff --git a/auto.def b/auto.def
index dc31fab..7e35f96 100644
--- a/auto.def
+++ b/auto.def
@@ -257,7 +257,7 @@ if {[cc-check-function-in-lib socket socket]} {
define-append LDLIBS [get-define lib_socket]
}
-cc-check-functions ualarm lstat fork system select execvpe
+cc-check-functions ualarm fork system select execvpe
cc-check-functions geteuid mkstemp isatty
cc-check-functions regcomp waitpid sigaction sys_signame sys_siglist isascii
cc-check-functions syslog opendir readlink sleep usleep pipe getaddrinfo utimes
@@ -301,6 +301,14 @@ cc-with {-includes fcntl.h} {
}
cc-check-lfs
+
+if {[get-define _FILE_OFFSET_BITS] != 64 || ![cc-check-functions stat64]} {
+ # Modern systems and really old systems have plain stat, fstat, lstat
+ cc-check-functions fstat lstat
+} else {
+ # But perhaps some 32 bit systems still require explicit use of the 64 bit versions
+ cc-check-functions fstat64 lstat64
+}
cc-check-functions fseeko ftello
define TCL_LIBRARY [get-define libdir]/jim
diff --git a/jim-file.c b/jim-file.c
index 4c8eabf..4a8380b 100644
--- a/jim-file.c
+++ b/jim-file.c
@@ -700,12 +700,12 @@ static int file_stat(Jim_Interp *interp, Jim_Obj *filename, jim_stat_t *sb)
return JIM_OK;
}
-#ifdef HAVE_LSTAT
+#ifdef Jim_LinkStat
static int file_lstat(Jim_Interp *interp, Jim_Obj *filename, jim_stat_t *sb)
{
const char *path = Jim_String(filename);
- if (lstat(path, sb) == -1) {
+ if (Jim_LinkStat(path, sb) == -1) {
Jim_SetResultFormatted(interp, "could not read \"%#s\": %s", filename, strerror(errno));
return JIM_ERR;
}
@@ -870,7 +870,7 @@ static int file_cmd_type(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
return JIM_OK;
}
-#ifdef HAVE_LSTAT
+#ifdef Jim_LinkStat
static int file_cmd_lstat(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
jim_stat_t sb;
diff --git a/jimiocompat.h b/jimiocompat.h
index 1f0507e..64aa4ff 100644
--- a/jimiocompat.h
+++ b/jimiocompat.h
@@ -70,9 +70,25 @@ int Jim_OpenForRead(const char *filename);
#define Jim_FileStat _fstat64
#else
- typedef struct stat jim_stat_t;
- #define Jim_Stat stat
- #define Jim_FileStat fstat
+ #if defined(HAVE_STAT64)
+ typedef struct stat64 jim_stat_t;
+ #define Jim_Stat stat64
+ #if defined(HAVE_FSTAT64)
+ #define Jim_FileStat fstat64
+ #endif
+ #if defined(HAVE_LSTAT64)
+ #define Jim_LinkStat lstat64
+ #endif
+ #else
+ typedef struct stat jim_stat_t;
+ #define Jim_Stat stat
+ #if defined(HAVE_FSTAT)
+ #define Jim_FileStat fstat
+ #endif
+ #if defined(HAVE_LSTAT)
+ #define Jim_LinkStat lstat
+ #endif
+ #endif
#if defined(HAVE_UNISTD_H)
#include <unistd.h>