Diff
Not logged in

Differences From Artifact [1c067e1b5b]:

To Artifact [54516d9f86]:


8
9
10
11
12
13
14
15

16
17
18
19
20
21
22
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22







-
+







 * Copyright 1991-1995 Karl Lehenbauer and Mark Diekhans.
 * Copyright (c) 1995 Sun Microsystems, Inc.
 * Copyright (c) 2004 by Kevin B. Kenny.  All rights reserved.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: tclClock.c,v 1.23.2.10 2004/12/09 23:00:30 dgp Exp $
 * RCS: @(#) $Id: tclClock.c,v 1.23.2.11 2005/07/26 04:11:52 dgp Exp $
 */

#include "tclInt.h"

/*
 * Windows has mktime.  The configurators do not check.
 */
162
163
164
165
166
167
168








169
170
171
172
173
174
175
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183







+
+
+
+
+
+
+
+







	      Tcl_NewStringObj("number too large to represent as a Posix time", 
			       -1) );
	Tcl_SetErrorCode( interp, "CLOCK", "argTooLarge", (char*) NULL );
	return TCL_ERROR;
    }
    TzsetIfNecessary();
    timeVal = ThreadSafeLocalTime( &tock );
    if ( timeVal == NULL ) {
	Tcl_SetObjResult(interp, 
			 Tcl_NewStringObj("localtime failed (clock "
					  "value may be too large/"
					  "small to represent)", -1));
	Tcl_SetErrorCode(interp, "CLOCK", "localtimeFailed", (char*) NULL);
	return TCL_ERROR;
    }

    /* Package the results */

    returnVec[0] = Tcl_NewIntObj( timeVal->tm_year + 1900 );
    returnVec[1] = Tcl_NewIntObj( timeVal->tm_mon + 1);
    returnVec[2] = Tcl_NewIntObj( timeVal->tm_mday );
    returnVec[3] = Tcl_NewIntObj( timeVal->tm_hour );
206
207
208
209
210
211
212

213
214
215
216





217
218



219
220
221
222
223
224
225
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230


231
232
233
234
235
236
237
238
239
240







+




+
+
+
+
+
-
-
+
+
+







{
    /*
     * Get a thread-local buffer to hold the returned time.
     */

    struct tm *tmPtr = (struct tm *)
	    Tcl_GetThreadData(&tmKey, (int) sizeof(struct tm));
    struct tm *sysTmPtr;
#ifdef HAVE_LOCALTIME_R
    localtime_r(timePtr, tmPtr);
#else
    Tcl_MutexLock(&clockMutex);
    sysTmPtr = localtime(timePtr);
    if ( sysTmPtr == NULL ) {
	Tcl_MutexUnlock( &clockMutex );
	return NULL;
    } else {
    memcpy((VOID *) tmPtr, (VOID *) localtime(timePtr), sizeof(struct tm));
    Tcl_MutexUnlock(&clockMutex);
	memcpy((VOID *) tmPtr, (VOID *) localtime(timePtr), sizeof(struct tm));
	Tcl_MutexUnlock(&clockMutex);
    }
#endif    
    return tmPtr;
}

/*
 *----------------------------------------------------------------------
 *