summaryrefslogtreecommitdiffstats
path: root/generic/tclIOUtil.c
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2009-12-28 12:55:48 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2009-12-28 12:55:48 (GMT)
commit000afb3098ed8c8148056fb2638e664b7e2cb3f2 (patch)
treebd4dc4243a573408e161da4ffd15e03e13792cd4 /generic/tclIOUtil.c
parentf9c66cfc9c6e599c938a2873b832c7a9c5b7efaf (diff)
downloadtcl-000afb3098ed8c8148056fb2638e664b7e2cb3f2.zip
tcl-000afb3098ed8c8148056fb2638e664b7e2cb3f2.tar.gz
tcl-000afb3098ed8c8148056fb2638e664b7e2cb3f2.tar.bz2
[Bug 942170]: Detect the st_blocks field of 'struct stat' correctly.
Diffstat (limited to 'generic/tclIOUtil.c')
-rw-r--r--generic/tclIOUtil.c32
1 files changed, 12 insertions, 20 deletions
diff --git a/generic/tclIOUtil.c b/generic/tclIOUtil.c
index 79769c9..a077bab 100644
--- a/generic/tclIOUtil.c
+++ b/generic/tclIOUtil.c
@@ -17,7 +17,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclIOUtil.c,v 1.165 2009/11/18 21:59:51 nijtmans Exp $
+ * RCS: @(#) $Id: tclIOUtil.c,v 1.166 2009/12/28 12:55:48 dkf Exp $
*/
#include "tclInt.h"
@@ -224,18 +224,14 @@ Tcl_Stat(
int ret;
Tcl_StatBuf buf;
Tcl_Obj *pathPtr = Tcl_NewStringObj(path,-1);
-#ifndef TCL_WIDE_INT_IS_LONG
- Tcl_WideInt tmp1, tmp2;
-#ifdef HAVE_ST_BLOCKS
- Tcl_WideInt tmp3;
-#endif
-#endif
Tcl_IncrRefCount(pathPtr);
ret = Tcl_FSStat(pathPtr, &buf);
Tcl_DecrRefCount(pathPtr);
if (ret != -1) {
#ifndef TCL_WIDE_INT_IS_LONG
+ Tcl_WideInt tmp1, tmp2, tmp3 = 0;
+
# define OUT_OF_RANGE(x) \
(((Tcl_WideInt)(x)) < Tcl_LongAsWide(LONG_MIN) || \
((Tcl_WideInt)(x)) > Tcl_LongAsWide(LONG_MAX))
@@ -254,23 +250,17 @@ Tcl_Stat(
tmp1 = (Tcl_WideInt) buf.st_ino;
tmp2 = (Tcl_WideInt) buf.st_size;
-#ifdef HAVE_ST_BLOCKS
+#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
tmp3 = (Tcl_WideInt) buf.st_blocks;
#endif
- if (OUT_OF_URANGE(tmp1) || OUT_OF_RANGE(tmp2)
-#ifdef HAVE_ST_BLOCKS
- || OUT_OF_RANGE(tmp3)
-#endif
- ) {
-#ifdef EFBIG
+ if (OUT_OF_URANGE(tmp1) || OUT_OF_RANGE(tmp2) || OUT_OF_RANGE(tmp3)) {
+#if defined(EFBIG)
errno = EFBIG;
-#else
-# ifdef EOVERFLOW
+#elif defined(EOVERFLOW)
errno = EOVERFLOW;
-# else
-# error "What status should be returned for file size out of range?"
-# endif
+#else
+#error "What status should be returned for file size out of range?"
#endif
return -1;
}
@@ -298,8 +288,10 @@ Tcl_Stat(
oldStyleBuf->st_atime = buf.st_atime;
oldStyleBuf->st_mtime = buf.st_mtime;
oldStyleBuf->st_ctime = buf.st_ctime;
-#ifdef HAVE_ST_BLOCKS
+#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
oldStyleBuf->st_blksize = buf.st_blksize;
+#endif
+#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
oldStyleBuf->st_blocks = (blkcnt_t) buf.st_blocks;
#endif
}