Win32OperatingSystem.st
changeset 12817 33771eb7d88b
parent 12815 ae5dc64d49a8
child 12818 b75404445906
equal deleted inserted replaced
12816:ff4a03e2da97 12817:33771eb7d88b
   478 
   478 
   479     tv.tv_sec  = 0;
   479     tv.tv_sec  = 0;
   480     tv.tv_usec = 0;
   480     tv.tv_usec = 0;
   481 
   481 
   482     if (readMode) {
   482     if (readMode) {
   483 	n = select (sock + 1, & fds, NULL, NULL, & tv);
   483         n = select (sock + 1, & fds, NULL, NULL, & tv);
   484     } else {
   484     } else {
   485 	n = select (sock + 1, NULL, & fds, NULL, & tv);
   485         n = select (sock + 1, NULL, & fds, NULL, & tv);
   486     }
   486     }
   487 
   487 
   488     if (n == 0) {
   488     if (n == 0) {
   489 	return (0);
   489         return (0);
   490     }
   490     }
   491 
   491 
   492     if (n > 0) {
   492     if (n > 0) {
   493 	return ((FD_ISSET (sock, & fds)) ? 1 : 0);
   493         return ((FD_ISSET (sock, & fds)) ? 1 : 0);
   494     }
   494     }
   495 
   495 
   496     winErrNo = WSAGetLastError();
   496     winErrNo = WSAGetLastError();
   497     switch (winErrNo) {
   497     switch (winErrNo) {
   498 	case WSAENOTSOCK:
   498         case WSAENOTSOCK:
   499 	    if (readMode) {
   499             if (readMode) {
   500 
   500 
   501 		DWORD  w = 0;
   501                 DWORD  w = 0;
   502 		HANDLE h = (HANDLE) _get_osfhandle (aFD);
   502                 HANDLE h = (HANDLE) _get_osfhandle (aFD);
   503 
   503 
   504 		if (PeekNamedPipe (h, 0, 0, 0, & w, 0)) {
   504                 if (PeekNamedPipe (h, 0, 0, 0, & w, 0)) {
   505 		    if( !__isWinNT || w > 0 )
   505                     if( !__isWinNT || w > 0 )
   506 			return (1);
   506                         return (1);
   507 
   507 
   508 		    return (0);
   508                     return (0);
   509 		}
   509                 }
   510 #if 0
   510 #if 0
   511 		console_fprintf(stderr, "_canAccessIOWithoutBlocking non Socket\n");
   511                 console_fprintf(stderr, "_canAccessIOWithoutBlocking non Socket\n");
   512 #endif
   512 #endif
   513 		return (-1);
   513                 return (-1);
   514 	    }
   514             }
   515 	    /* in writeMode we return allways true for none-sockets */
   515             /* in writeMode we return allways true for none-sockets */
   516 	    return (1);
   516             return (1);
   517 
   517 
   518 	case WSAEINPROGRESS:
   518         case WSAEINPROGRESS:
   519 	case WSAEWOULDBLOCK:
   519         case WSAEWOULDBLOCK:
   520 	    return (0);
   520             return (0);
   521 
   521 
   522 	default:
   522         default:
   523 	    console_fprintf(stderr, "_canAccessIOWithoutBlocking -> %d (0x%x)\n", winErrNo, winErrNo);
   523             console_fprintf(stderr, "_canAccessIOWithoutBlocking -> %d (0x%x)\n", winErrNo, winErrNo);
   524 	    return (-1);
   524             return (-1);
   525     }
   525     }
   526 
   526 
   527     /* not reached */
   527     /* not reached */
   528     return (0);
   528     return (0);
   529 }
   529 }
   541 __get_functionAddress(HINSTANCE *pLibHandle, char *libraryName, char *functionName)
   541 __get_functionAddress(HINSTANCE *pLibHandle, char *libraryName, char *functionName)
   542 {
   542 {
   543     FARPROC entry;
   543     FARPROC entry;
   544 
   544 
   545     if (*pLibHandle == NULL) {
   545     if (*pLibHandle == NULL) {
   546 	*pLibHandle = LoadLibrary(libraryName);
   546         *pLibHandle = LoadLibrary(libraryName);
   547     }
   547     }
   548     entry = GetProcAddress(*pLibHandle, functionName);
   548     entry = GetProcAddress(*pLibHandle, functionName);
   549     return entry;
   549     return entry;
   550 }
   550 }
   551 
   551 
   572 {
   572 {
   573     static HINSTANCE libHandle = NULL;
   573     static HINSTANCE libHandle = NULL;
   574 
   574 
   575     return __get_functionAddress(&libHandle, "ole32.DLL", functionName);
   575     return __get_functionAddress(&libHandle, "ole32.DLL", functionName);
   576 }
   576 }
       
   577 
       
   578 void TimetToFileTime( time_t t, LPFILETIME pft )
       
   579 {
       
   580     LONGLONG ll = Int32x32To64(t, 10000000) + 116444736000000000;
       
   581     pft->dwLowDateTime = (DWORD) ll;
       
   582     pft->dwHighDateTime = ll >>32;
       
   583 }
       
   584 
   577 
   585 
   578 %}
   586 %}
   579 ! !
   587 ! !
   580 
   588 
   581 !Win32OperatingSystem class methodsFor:'documentation'!
   589 !Win32OperatingSystem class methodsFor:'documentation'!
  8386     }
  8394     }
  8387 
  8395 
  8388     if (P_RtlGenRandom == 0) {
  8396     if (P_RtlGenRandom == 0) {
  8389         HINSTANCE hAdvapi32 = LoadLibrary("advapi32.dll");
  8397         HINSTANCE hAdvapi32 = LoadLibrary("advapi32.dll");
  8390         // console_printf("hAdvapi32: %x\n", hAdvapi32);
  8398         // console_printf("hAdvapi32: %x\n", hAdvapi32);
  8391         console_printf("hAdvapi32: %x\n", hAdvapi32);
       
  8392         if (hAdvapi32) {
  8399         if (hAdvapi32) {
  8393             P_RtlGenRandom = (BOOL (__stdcall *)(PVOID , ULONG))
  8400             P_RtlGenRandom = (BOOL (__stdcall *)(PVOID , ULONG))
  8394                                 GetProcAddress(hAdvapi32, "SystemFunction036");
  8401                                 GetProcAddress(hAdvapi32, "SystemFunction036");
  8395             console_printf("P_RtlGenRandom: %x\n", P_RtlGenRandom);
  8402             console_printf("P_RtlGenRandom: %x\n", P_RtlGenRandom);
  8396             if (P_RtlGenRandom == 0) {
  8403             if (P_RtlGenRandom == 0) {
  9732 %}
  9739 %}
  9733 ! !
  9740 ! !
  9734 
  9741 
  9735 !Win32OperatingSystem class methodsFor:'time and date'!
  9742 !Win32OperatingSystem class methodsFor:'time and date'!
  9736 
  9743 
  9737 computeDatePartsOf:osTime for:aBlock
       
  9738     "compute year, month and day from the OS time, osTime
       
  9739      and evaluate the argument, a 3-arg block with these.
       
  9740      Conversion is to localtime including any daylight saving adjustments."
       
  9741 
       
  9742     |year month day osSeconds|
       
  9743 
       
  9744     osSeconds := osTime // 1000.
       
  9745 %{
       
  9746     struct tm* tmPtr;
       
  9747     struct tm tmValue;
       
  9748     INT t;
       
  9749     time_t tt;
       
  9750 
       
  9751     t = __longIntVal(osSeconds);
       
  9752     tt = (time_t)t;
       
  9753 
       
  9754 #ifdef __BORLANDC__
       
  9755     tmPtr = localtime(&tt);
       
  9756 #else
       
  9757     /* be thread safe */
       
  9758     if (localtime_s(&tmValue, &tt) == 0)
       
  9759 	tmPtr = &tmValue;
       
  9760     else
       
  9761 	tmPtr = NULL;
       
  9762 #endif
       
  9763 
       
  9764     if (tmPtr != NULL) {
       
  9765 	year = __mkSmallInteger(tmPtr->tm_year + 1900);
       
  9766 	month = __mkSmallInteger(tmPtr->tm_mon + 1);
       
  9767 	day = __mkSmallInteger(tmPtr->tm_mday);
       
  9768     }
       
  9769 %}.
       
  9770     year isNil ifTrue:[
       
  9771 	self primitiveFailed
       
  9772     ].
       
  9773     aBlock value:year value:month value:day
       
  9774 
       
  9775     "
       
  9776      OperatingSystem computeDatePartsOf:0 for:[:y :m :d |
       
  9777 	y printCR. m printCR. d printCR
       
  9778      ]
       
  9779     "
       
  9780 
       
  9781     "Modified: / 06-07-2006 / 18:18:04 / cg"
       
  9782 !
       
  9783 
       
  9784 computeOSTimeFromUTCYear:y month:m day:d hour:h minute:min second:s millisecond:millis
  9744 computeOSTimeFromUTCYear:y month:m day:d hour:h minute:min second:s millisecond:millis
  9785     "return the OS-dependent time for the given time and day.
  9745     "return the OS-dependent time for the given time and day.
  9786      The arguments are assumed to be in UTC time."
  9746      The arguments are assumed to be in UTC time."
  9787 
  9747 
  9788     |osSeconds|
  9748     |osSeconds|
  9791     struct tm tm;
  9751     struct tm tm;
  9792 
  9752 
  9793     if (__bothSmallInteger(y, m)
  9753     if (__bothSmallInteger(y, m)
  9794      && __bothSmallInteger(d, h)
  9754      && __bothSmallInteger(d, h)
  9795      && __bothSmallInteger(min, s)) {
  9755      && __bothSmallInteger(min, s)) {
  9796 	time_t t;
  9756         time_t t;
  9797 	TIME_ZONE_INFORMATION tzInfo;
  9757 
  9798 	int gmtoffMinutes;
  9758         tm.tm_hour = __intVal(h);
  9799 
  9759         tm.tm_min = __intVal(min);
  9800 	if (GetTimeZoneInformation(&tzInfo) < 0) goto error;
  9760         tm.tm_sec = __intVal(s);
  9801 
  9761 
  9802 	tm.tm_hour = __intVal(h);
  9762         tm.tm_year = __intVal(y) - 1900;
  9803 	tm.tm_min = __intVal(min);
  9763         tm.tm_mon = __intVal(m) - 1;
  9804 	tm.tm_sec = __intVal(s);
  9764         tm.tm_mday = __intVal(d);
  9805 
  9765         tm.tm_isdst = 0;
  9806 	tm.tm_year = __intVal(y) - 1900;
  9766 
  9807 	tm.tm_mon = __intVal(m) - 1;
  9767         t = mktime(&tm);
  9808 	tm.tm_mday = __intVal(d);
  9768 
  9809 	tm.tm_isdst = -1;
  9769         osSeconds = __MKUINT((INT)t);
  9810 
       
  9811 	t = mktime(&tm);
       
  9812 
       
  9813 	gmtoffMinutes = tzInfo.Bias;
       
  9814 	if (tm.tm_isdst) {
       
  9815 	    gmtoffMinutes += tzInfo.DaylightBias;
       
  9816 	} else {
       
  9817 	    gmtoffMinutes += tzInfo.StandardBias;
       
  9818 	}
       
  9819 	t = t - gmtoffMinutes*60;
       
  9820 	osSeconds = __MKUINT((INT)t);
       
  9821     }
  9770     }
  9822 error:;
  9771 error:;
  9823 %}.
  9772 %}.
  9824     osSeconds notNil ifTrue:[
  9773     osSeconds notNil ifTrue:[
  9825 	^ osSeconds * 1000 + millis
  9774         ^ osSeconds * 1000 + millis
  9826     ].
  9775     ].
  9827     ^ self primitiveFailed
  9776     ^ self primitiveFailed
  9828 
  9777 
  9829     "
  9778     "
  9830      OperatingSystem computeOSTimeFromUTCYear:1970 month:1 day:1 hour:0 minute:0 second:0 millisecond:0
  9779      OperatingSystem computeOSTimeFromUTCYear:1970 month:1 day:1 hour:0 minute:0 second:0 millisecond:0
  9865 
  9814 
  9866     "
  9815     "
  9867      OperatingSystem computeOSTimeFromYear:1970 month:1 day:1 hour:0 minute:0 seconds:0 millis:0
  9816      OperatingSystem computeOSTimeFromYear:1970 month:1 day:1 hour:0 minute:0 seconds:0 millis:0
  9868     "
  9817     "
  9869 
  9818 
  9870 !
       
  9871 
       
  9872 computeTimePartsOf:osTime for:aBlock
       
  9873     "compute hours, minutes, seconds and milliseconds from the osTime
       
  9874      and evaluate the argument, a 4-arg block with these.
       
  9875      Conversion is to localtime including any daylight saving adjustments."
       
  9876 
       
  9877     |hours minutes seconds millis osSeconds|
       
  9878 
       
  9879     osSeconds := osTime // 1000.
       
  9880     millis := osTime \\ 1000.
       
  9881 %{
       
  9882     struct tm *tmPtr;
       
  9883     struct tm tmValue;
       
  9884     INT t;
       
  9885     time_t tt;
       
  9886 
       
  9887     t = __longIntVal(osSeconds);
       
  9888     tt = (time_t)t;
       
  9889 
       
  9890 #ifdef __BORLANDC__
       
  9891     tmPtr = localtime(&tt);
       
  9892 #else
       
  9893     /* be thread safe */
       
  9894     if (localtime_s(&tmValue, &tt) == 0)
       
  9895 	tmPtr = &tmValue;
       
  9896     else
       
  9897 	tmPtr = NULL;
       
  9898 #endif
       
  9899 
       
  9900     if (tmPtr != NULL) {
       
  9901 	hours = __mkSmallInteger(tmPtr->tm_hour);
       
  9902 	minutes = __mkSmallInteger(tmPtr->tm_min);
       
  9903 	seconds = __mkSmallInteger(tmPtr->tm_sec);
       
  9904     }
       
  9905 %}.
       
  9906     hours isNil ifTrue:[
       
  9907 	self primitiveFailed
       
  9908     ].
       
  9909     aBlock value:hours value:minutes value:seconds value:millis
       
  9910 
       
  9911     "
       
  9912      OperatingSystem computeTimePartsOf:100 for:[:h :m :s :milli |
       
  9913 	h printCR. m printCR. s printCR. millis printCR
       
  9914      ]
       
  9915     "
       
  9916 
       
  9917     "Modified: / 06-07-2006 / 18:18:39 / cg"
       
  9918 !
       
  9919 
       
  9920 computeUTCTimeAndDateFrom:osTime
       
  9921     "given an OS-dependent time in osTime, return an Array
       
  9922      containing year, month, day, hour, minute and seconds,
       
  9923      offset to UTC, daylight savings time flag, milliseconds,
       
  9924      dayInYear (1..) and dayInWeek (1..).
       
  9925      Conversion is to UTC."
       
  9926 
       
  9927     |year month day hours minutes seconds millis utcOffset
       
  9928      dst yDay wDay osSeconds ret|
       
  9929 
       
  9930     millis := osTime \\ 1000.
       
  9931     osSeconds := osTime // 1000.
       
  9932 %{
       
  9933     struct tm *tmPtr;
       
  9934     struct tm *gmTmPtr;
       
  9935     long t;
       
  9936 
       
  9937     t = __longIntVal(osSeconds);
       
  9938 
       
  9939     tmPtr = gmtime(&t);
       
  9940     hours = __mkSmallInteger(tmPtr->tm_hour);
       
  9941     minutes = __mkSmallInteger(tmPtr->tm_min);
       
  9942     seconds = __mkSmallInteger(tmPtr->tm_sec);
       
  9943 
       
  9944     year = __mkSmallInteger(tmPtr->tm_year + 1900);
       
  9945     month = __mkSmallInteger(tmPtr->tm_mon + 1);
       
  9946     day = __mkSmallInteger(tmPtr->tm_mday);
       
  9947 
       
  9948     yDay = __mkSmallInteger(tmPtr->tm_yday + 1);
       
  9949     wDay = __mkSmallInteger(tmPtr->tm_wday == 0 ? 7 : tmPtr->tm_wday);
       
  9950     dst = (tmPtr->tm_isdst == 0) ? false : true;
       
  9951 
       
  9952 #ifdef WINDOWS_IS_POSIX_CONFORM_WHICH_IT_IS_NOT
       
  9953     utcOffset = __MKINT(tmPtr->tm_gmtoff);
       
  9954 #else
       
  9955     {
       
  9956 	TIME_ZONE_INFORMATION tzInfo;
       
  9957 	int gmtoffMinutes = 0;
       
  9958 
       
  9959 	if (GetTimeZoneInformation(&tzInfo) < 0) goto error;
       
  9960 	gmtoffMinutes = tzInfo.Bias;
       
  9961 	if (tmPtr->tm_isdst) {
       
  9962 	    gmtoffMinutes += tzInfo.DaylightBias;
       
  9963 	} else {
       
  9964 	    gmtoffMinutes += tzInfo.StandardBias;
       
  9965 	}
       
  9966 
       
  9967 	utcOffset = __MKINT(gmtoffMinutes*60);
       
  9968     }
       
  9969 #endif
       
  9970 error:;
       
  9971 %}.
       
  9972     "I would love to have SELF-like inline objects ..."
       
  9973     ret := Array new:11.
       
  9974     ret at:1 put:year.
       
  9975     ret at:2 put:month.
       
  9976     ret at:3 put:day.
       
  9977     ret at:4 put:hours.
       
  9978     ret at:5 put:minutes.
       
  9979     ret at:6 put:seconds.
       
  9980     ret at:7 put:utcOffset.
       
  9981     ret at:8 put:dst.
       
  9982     ret at:9 put:millis.
       
  9983     ret at:10 put:yDay.
       
  9984     ret at:11 put:wDay.
       
  9985     ^ ret
       
  9986 
       
  9987     "
       
  9988      OperatingSystem computeUTCTimeAndDateFrom:0
       
  9989      OperatingSystem computeUTCTimeAndDateFrom:self getOSTime
       
  9990     "
       
  9991 !
  9819 !
  9992 
  9820 
  9993 getMicrosecondTime
  9821 getMicrosecondTime
  9994     "This returns a microsecond timer value.
  9822     "This returns a microsecond timer value.
  9995      The returned value is a 64bit value
  9823      The returned value is a 64bit value
 10064      others since 1900. The Time classes are prepared for this, and
  9892      others since 1900. The Time classes are prepared for this, and
 10065      converts as appropriate (by using my fromOSTime: conversion methods).
  9893      converts as appropriate (by using my fromOSTime: conversion methods).
 10066 
  9894 
 10067      Dont use this method in application code since it is an internal (private)
  9895      Dont use this method in application code since it is an internal (private)
 10068      interface. For compatibility with ST-80, use Time>>millisecondClockValue.
  9896      interface. For compatibility with ST-80, use Time>>millisecondClockValue.
 10069      or use instances of Time, Date or Timestamp to work with.
  9897      or use instances of Time, Date or Timestamp to work with."
 10070     "
       
 10071 
  9898 
 10072     |seconds millis|
  9899     |seconds millis|
 10073 
  9900 
 10074 %{
  9901 %{
 10075 
  9902     FILETIME fileTime;
 10076     long t;
  9903     LONGLONG nsTime100;             /* number 100ns since 160x */
 10077 
  9904     LONGLONG millisSince1970;
 10078 #if !defined(HAS_GETTIMEOFDAY)
  9905 
 10079 # if defined(HAS_FTIME)
  9906     GetSystemTimeAsFileTime(&fileTime);
 10080     struct timeb timebuffer;
  9907     nsTime100 = ((LONGLONG)fileTime.dwHighDateTime << 32) + fileTime.dwLowDateTime;
 10081 
  9908     millisSince1970 = (nsTime100 / 10000) - 11644473600000;
 10082     ftime(&timebuffer);
  9909 
 10083     seconds = __MKUINT(timebuffer.time);
  9910     /* do large integer arithmethic in smalltalk */
 10084     millis = __MKUINT(timebuffer.millitm);
  9911     seconds = __MKUINT((unsigned INT)(millisSince1970 / 1000));
 10085 #   define HAVE_TIME
  9912     millis  = __mkSmallInteger((unsigned INT)(millisSince1970 % 1000));
 10086 # endif
       
 10087 
       
 10088 # ifndef HAVE_TIME
       
 10089 #  ifdef MSDOS_LIKE
       
 10090 #   ifdef __BORLANDC__
       
 10091     struct timeb timebuffer;
       
 10092     ftime(&timebuffer);
       
 10093 #   else
       
 10094     struct _timeb timebuffer;
       
 10095     _ftime(&timebuffer);
       
 10096 #   endif
       
 10097     seconds = __MKUINT(timebuffer.time);
       
 10098     millis = __MKUINT(timebuffer.millitm);
       
 10099 #   define HAVE_TIME
       
 10100 #  endif
       
 10101 # endif
       
 10102 #endif
       
 10103 
       
 10104 #ifndef HAVE_TIME
       
 10105     /* assume HAS_GETTIMEOFDAY
       
 10106      * - will result in a linkage error
       
 10107      * if not fixed.
       
 10108      */
       
 10109     /*
       
 10110      * bsd time
       
 10111      */
       
 10112     struct timeval tb;
       
 10113     struct timezone tzb;
       
 10114 
       
 10115     gettimeofday(&tb, &tzb);
       
 10116 
       
 10117     seconds = __MKUINT(tb.tv_sec);
       
 10118     millis = __MKUINT(tb.tv_usec / 1000);
       
 10119 #endif
       
 10120 
       
 10121 #undef HAVE_TIME
       
 10122 
       
 10123 %}.
  9913 %}.
 10124     ^ (seconds * 1000) + millis
  9914     ^ (seconds * 1000) + millis
 10125 
  9915 
 10126     "
  9916     "
 10127      OperatingSystem getOSTime printCR.
  9917      OperatingSystem getOSTime.
 10128      Delay waitForSeconds:0.2.
  9918      Delay waitForSeconds:0.2.
 10129      OperatingSystem getOSTime printCR.
  9919      OperatingSystem getOSTime printCR.
 10130     "
  9920     "
 10131 !
  9921 !
 10132 
  9922 
 10241 timeInfoFromSeconds:osSeconds milliseconds:osMilliseconds localTime:isLocalTime
 10031 timeInfoFromSeconds:osSeconds milliseconds:osMilliseconds localTime:isLocalTime
 10242     "return a timeInfo structure containing values for the given
 10032     "return a timeInfo structure containing values for the given
 10243      OS-second value.
 10033      OS-second value.
 10244      An internal helper"
 10034      An internal helper"
 10245 
 10035 
 10246     |year month day hours minutes seconds utcOffset
 10036     |year month day hours minutes seconds utcOffset dstOffset
 10247      dst yDay wDay info reason|
 10037      dst yDay weekDay info reason|
 10248 
 10038 
 10249 %{
 10039 %{
 10250     struct tm *tmPtr;
       
 10251     struct tm tmValue;
       
 10252     UINT t;
 10040     UINT t;
 10253     time_t tt;
 10041     FILETIME fileTime, localFileTime;
       
 10042     SYSTEMTIME sysTime;
 10254 
 10043 
 10255     t = __longIntVal(osSeconds);
 10044     t = __longIntVal(osSeconds);
 10256 
 10045 
 10257     /* try cache */
 10046     /* try cache */
 10258     {
 10047     {
 10268             if (lastTimeInfo != nil) {
 10057             if (lastTimeInfo != nil) {
 10269                 RETURN (lastTimeInfo);
 10058                 RETURN (lastTimeInfo);
 10270             }
 10059             }
 10271         }
 10060         }
 10272     }
 10061     }
 10273     if (t == 0) {
 10062 
 10274         reason = @symbol(invalidOSTime);
 10063     TimetToFileTime((time_t)t, &fileTime);
 10275         goto error;
       
 10276     }
       
 10277 
       
 10278     tt = (time_t)t;
       
 10279 
 10064 
 10280     if (isLocalTime == true) {
 10065     if (isLocalTime == true) {
 10281 #ifdef __BORLANDC__
 10066         TIME_ZONE_INFORMATION tzInfo;
 10282         tmPtr = localtime(&tt);
 10067         int tzState;
 10283 #else
 10068         LONGLONG longTime;
 10284         /* be thread safe */
 10069 
 10285         if (localtime_s(&tmValue, &tt) == 0)
 10070         FileTimeToLocalFileTime(&fileTime, &localFileTime);
 10286             tmPtr = &tmValue;
 10071         FileTimeToSystemTime(&localFileTime, &sysTime);
 10287         else
 10072 
 10288             tmPtr = NULL;
 10073         longTime = ((LONGLONG)fileTime.dwHighDateTime << 32) + fileTime.dwLowDateTime;
 10289 #endif
 10074         longTime -= ((LONGLONG)localFileTime.dwHighDateTime << 32) + localFileTime.dwLowDateTime;
 10290         if (tmPtr == NULL) {
 10075         utcOffset = __mkSmallInteger((INT)(longTime / 10000000));
 10291             reason = @symbol(localtimeConversionFailed);
 10076 
       
 10077         if ((tzState = GetTimeZoneInformation(&tzInfo)) < 0) {
       
 10078             reason = @symbol(getTimeZoneFailed);
 10292             goto error;
 10079             goto error;
 10293         }
 10080         }
 10294 
 10081         dstOffset = __mkSmallInteger((tzInfo.Bias + tzInfo.DaylightBias) * 60);
 10295 #ifdef WINDOWS_IS_POSIX_CONFORM_WHICH_IT_IS_NOT
       
 10296         utcOffset = __MKINT(tmPtr->tm_gmtoff);
       
 10297 #else
       
 10298         {
       
 10299             TIME_ZONE_INFORMATION tzInfo;
       
 10300             int tzState, gmtoffMinutes = 0;
       
 10301 
       
 10302             if ((tzState = GetTimeZoneInformation(&tzInfo)) < 0) {
       
 10303                 reason = @symbol(getTimeZoneFailed);
       
 10304                 goto error;
       
 10305             }
       
 10306             gmtoffMinutes = tzInfo.Bias;
       
 10307             if (tzState == TIME_ZONE_ID_DAYLIGHT) {
       
 10308                 gmtoffMinutes += tzInfo.DaylightBias;
       
 10309                 tmPtr->tm_isdst = 1;
       
 10310             } else {
       
 10311                 gmtoffMinutes += tzInfo.StandardBias;
       
 10312                 tmPtr->tm_isdst = 0;
       
 10313             }
       
 10314             utcOffset = __MKINT(gmtoffMinutes*60);
       
 10315         }
       
 10316 #endif
       
 10317     } else {
 10082     } else {
 10318 #ifdef __BORLANDC__
 10083         FileTimeToSystemTime(&fileTime, &sysTime);
 10319         tmPtr = gmtime(&tt);
 10084         utcOffset = dstOffset = __mkSmallInteger(0);
 10320 #else
 10085     }
 10321         /* be thread safe */
 10086 
 10322         if (gmtime_s(&tmValue, &tt) == 0)
 10087     hours = __mkSmallInteger(sysTime.wHour);
 10323             tmPtr = &tmValue;
 10088     minutes = __mkSmallInteger(sysTime.wMinute);
 10324         else
 10089     seconds = __mkSmallInteger(sysTime.wSecond);
 10325             tmPtr = NULL;
 10090 
 10326 #endif
 10091     year = __mkSmallInteger(sysTime.wYear);
 10327         if (tmPtr == NULL) {
 10092     month = __mkSmallInteger(sysTime.wMonth);
 10328             reason = @symbol(conversionToGMTimeFailed);
 10093     day = __mkSmallInteger(sysTime.wDay);
 10329             goto error;
 10094 
 10330         }
 10095     weekDay = __mkSmallInteger(sysTime.wDayOfWeek == 0 ? 7 : sysTime.wDayOfWeek);
 10331         utcOffset = __mkSmallInteger(0);
       
 10332     }
       
 10333 
       
 10334     hours = __mkSmallInteger(tmPtr->tm_hour);
       
 10335     minutes = __mkSmallInteger(tmPtr->tm_min);
       
 10336     seconds = __mkSmallInteger(tmPtr->tm_sec);
       
 10337 
       
 10338     year = __mkSmallInteger(tmPtr->tm_year + 1900);
       
 10339     month = __mkSmallInteger(tmPtr->tm_mon + 1);
       
 10340     day = __mkSmallInteger(tmPtr->tm_mday);
       
 10341 
       
 10342     yDay = __mkSmallInteger(tmPtr->tm_yday+1);
       
 10343     wDay = __mkSmallInteger(tmPtr->tm_wday == 0 ? 7 : tmPtr->tm_wday);
       
 10344 
       
 10345     dst = (tmPtr->tm_isdst == 0) ? false : true;
       
 10346 error:;
 10096 error:;
 10347 %}.
 10097 %}.
 10348     dst isNil ifTrue:[
 10098     year isNil ifTrue:[
 10349         ^ self primitiveFailed
 10099         ^ self primitiveFailed
 10350     ].
 10100     ].
 10351 
 10101 
 10352     info := self timeInfoClass new.
 10102     info := self timeInfoClass new.
 10353     info
 10103     info
 10357         hours:hours
 10107         hours:hours
 10358         minutes:minutes
 10108         minutes:minutes
 10359         seconds:seconds
 10109         seconds:seconds
 10360         milliseconds:osMilliseconds
 10110         milliseconds:osMilliseconds
 10361         utcOffset:utcOffset
 10111         utcOffset:utcOffset
 10362         dst:dst
 10112         dst:(utcOffset = dstOffset)
 10363         dayInYear:yDay
 10113         dayInYear:yDay
 10364         dayInWeek:wDay.
 10114         dayInWeek:weekDay.
 10365 
 10115 
 10366     LastTimeInfo := info.
 10116     LastTimeInfo := info.
 10367     LastTimeInfoSeconds := osSeconds.
 10117     LastTimeInfoSeconds := osSeconds.
 10368     LastTimeInfoMilliseconds := osMilliseconds.
 10118     LastTimeInfoMilliseconds := osMilliseconds.
 10369     LastTimeInfoIsLocal := isLocalTime.
 10119     LastTimeInfoIsLocal := isLocalTime.
 10373     "
 10123     "
 10374      OperatingSystem timeInfoFromSeconds:0 milliseconds:0 localTime:false
 10124      OperatingSystem timeInfoFromSeconds:0 milliseconds:0 localTime:false
 10375      OperatingSystem timeInfoFromSeconds:0 milliseconds:0 localTime:false
 10125      OperatingSystem timeInfoFromSeconds:0 milliseconds:0 localTime:false
 10376      OperatingSystem timeInfoFromSeconds:3600 milliseconds:0 localTime:true
 10126      OperatingSystem timeInfoFromSeconds:3600 milliseconds:0 localTime:true
 10377      OperatingSystem timeInfoFromSeconds:Timestamp now utcSecondsSince1970 milliseconds:0 localTime:true
 10127      OperatingSystem timeInfoFromSeconds:Timestamp now utcSecondsSince1970 milliseconds:0 localTime:true
       
 10128      OperatingSystem timeInfoFromSeconds:Timestamp now utcSecondsSince1970 milliseconds:0 localTime:false
 10378     "
 10129     "
 10379 
 10130 
 10380     "Modified: / 06-07-2006 / 18:18:56 / cg"
 10131     "Modified: / 06-07-2006 / 18:18:56 / cg"
 10381 !
 10132 !
 10382 
 10133 
 16497 ! !
 16248 ! !
 16498 
 16249 
 16499 !Win32OperatingSystem class methodsFor:'documentation'!
 16250 !Win32OperatingSystem class methodsFor:'documentation'!
 16500 
 16251 
 16501 version
 16252 version
 16502     ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.392 2010-03-29 11:24:05 stefan Exp $'
 16253     ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.393 2010-03-29 18:03:08 stefan Exp $'
 16503 !
 16254 !
 16504 
 16255 
 16505 version_CVS
 16256 version_CVS
 16506     ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.392 2010-03-29 11:24:05 stefan Exp $'
 16257     ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.393 2010-03-29 18:03:08 stefan Exp $'
 16507 ! !
 16258 ! !
 16508 
 16259 
 16509 Win32OperatingSystem initialize!
 16260 Win32OperatingSystem initialize!
 16510 Win32OperatingSystem::PerformanceData initialize!
 16261 Win32OperatingSystem::PerformanceData initialize!
 16511 Win32OperatingSystem::RegistryEntry initialize!
 16262 Win32OperatingSystem::RegistryEntry initialize!