summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvincentdarley <vincentdarley>2004-11-02 12:13:35 (GMT)
committervincentdarley <vincentdarley>2004-11-02 12:13:35 (GMT)
commit86bd1359ad8004bb5152048c27cf0b7b68903db4 (patch)
tree54c0de37ce916e8abe8f7ff131a9cf939dc307c5
parentf1990817283b9831ee0022ac4d46e1408c3ace82 (diff)
downloadtcl-86bd1359ad8004bb5152048c27cf0b7b68903db4.zip
tcl-86bd1359ad8004bb5152048c27cf0b7b68903db4.tar.gz
tcl-86bd1359ad8004bb5152048c27cf0b7b68903db4.tar.bz2
TclpUTime simplification
-rw-r--r--ChangeLog5
-rw-r--r--win/tclWinFile.c54
2 files changed, 34 insertions, 25 deletions
diff --git a/ChangeLog b/ChangeLog
index 1dbd126..63e3a2b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2004-11-02 Vince Darley <vincentdarley@users.sourceforge.net>
+
+ * win/tclWinFile.c: Simplify TclpUtime to use Tcl_FSGetNativePath,
+ and add comments.
+
2004-11-02 Donal K. Fellows <donal.k.fellows@man.ac.uk>
* generic/tclInt.h: Change uses of EXTERN to MODULE_SCOPE (defined
diff --git a/win/tclWinFile.c b/win/tclWinFile.c
index ab9a601..ca2eeba 100644
--- a/win/tclWinFile.c
+++ b/win/tclWinFile.c
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclWinFile.c,v 1.69 2004/11/01 16:58:37 kennykb Exp $
+ * RCS: @(#) $Id: tclWinFile.c,v 1.70 2004/11/02 12:13:36 vincentdarley Exp $
*/
//#define _WIN32_WINNT 0x0500
@@ -1958,6 +1958,10 @@ NativeStat(nativePath, statPtr, checkLinks)
* NativeStatMode --
*
* Calculate just the 'st_mode' field of a 'stat' structure.
+ *
+ * In many places we don't need the full stat structure, and
+ * it's much faster just to calculate these pieces, if that's
+ * all we need.
*
*----------------------------------------------------------------------
*/
@@ -2000,13 +2004,13 @@ NativeStatMode(DWORD attr, int checkLinks, int isExec)
*/
static time_t
-ToCTime( FILETIME fileTime ) /* UTC time */
+ToCTime(FILETIME fileTime) /* UTC time */
{
LARGE_INTEGER convertedTime;
convertedTime.LowPart = fileTime.dwLowDateTime;
convertedTime.HighPart = (LONG) fileTime.dwHighDateTime;
- return (time_t) ( (convertedTime.QuadPart
- - (Tcl_WideInt) POSIX_EPOCH_AS_FILETIME)
+ return (time_t) ((convertedTime.QuadPart
+ - (Tcl_WideInt) POSIX_EPOCH_AS_FILETIME)
/ (Tcl_WideInt) 10000000);
}
@@ -2025,8 +2029,8 @@ ToCTime( FILETIME fileTime ) /* UTC time */
*/
static void
-FromCTime( time_t posixTime,
- FILETIME* fileTime ) /* UTC Time */
+FromCTime(time_t posixTime,
+ FILETIME* fileTime) /* UTC Time */
{
LARGE_INTEGER convertedTime;
convertedTime.QuadPart = ((LONGLONG) posixTime) * 10000000
@@ -2932,28 +2936,28 @@ TclpUtime(pathPtr, tval)
struct utimbuf *tval; /* New modification date structure */
{
int res = 0;
- char* path;
- int pathLen;
- Tcl_DString buffer;
- TCHAR* winPath;
HANDLE fileHandle;
- FILETIME lastAccessTime;
- FILETIME lastModTime;
- FromCTime( tval->actime, &lastAccessTime );
- FromCTime( tval->modtime, &lastModTime );
- path = Tcl_GetStringFromObj( pathPtr, &pathLen );
- winPath = Tcl_WinUtfToTChar( path, pathLen, &buffer );
- fileHandle = (tclWinProcs->createFileProc)
- ( winPath, FILE_WRITE_ATTRIBUTES, 0, NULL, OPEN_EXISTING,
- FILE_ATTRIBUTE_NORMAL, NULL );
- if ( fileHandle == INVALID_HANDLE_VALUE
- || !SetFileTime( fileHandle, NULL, &lastAccessTime, &lastModTime ) ) {
- TclWinConvertError( GetLastError() );
+ FILETIME lastAccessTime, lastModTime;
+
+ FromCTime(tval->actime, &lastAccessTime);
+ FromCTime(tval->modtime, &lastModTime);
+
+ /*
+ * We use the native APIs (not 'utime') because there are
+ * some daylight savings complications that utime gets wrong.
+ */
+ fileHandle = (tclWinProcs->createFileProc) (
+ (CONST TCHAR*) Tcl_FSGetNativePath(pathPtr),
+ FILE_WRITE_ATTRIBUTES, 0, NULL, OPEN_EXISTING,
+ FILE_ATTRIBUTE_NORMAL, NULL);
+
+ if (fileHandle == INVALID_HANDLE_VALUE
+ || !SetFileTime(fileHandle, NULL, &lastAccessTime, &lastModTime)) {
+ TclWinConvertError(GetLastError());
res = -1;
}
- if ( fileHandle != INVALID_HANDLE_VALUE ) {
- CloseHandle( fileHandle );
+ if (fileHandle != INVALID_HANDLE_VALUE) {
+ CloseHandle(fileHandle);
}
- Tcl_DStringFree( &buffer );
return res;
}